Don't show ".gitcookies have credentials" if no creds

Running `git cl creds-check` without any credentials will show:

```
Your .gitcookies have credentials for these hosts:
No Git/Gerrit credentials found
```

The first line of the output should not assume that there are hosts. Don't show this line if credentials are not found.

Change-Id: Ie6eba3518f4b270eef5fbe0c51b4494762a3aef4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5663779
Reviewed-by: Scott Lee <ddoman@chromium.org>
Auto-Submit: Gavin Mak <gavinmak@google.com>
Commit-Queue: Scott Lee <ddoman@chromium.org>
changes/79/5663779/5
Gavin Mak 10 months ago committed by LUCI CQ
parent 280b823136
commit ea802a77b7

@ -3742,10 +3742,11 @@ class _GitCookiesChecker(object):
def print_current_creds(self):
hosts = sorted(self.get_hosts_with_creds())
if not hosts:
print('No Git/Gerrit credentials found')
print('No Git/Gerrit credentials found.')
return
lengths = [max(map(len, (row[i] for row in hosts))) for i in range(3)]
header = [('Host', 'User', 'Which file'), ['=' * l for l in lengths]]
print('Your .gitcookies have credentials for these hosts:')
for row in (header + hosts):
print('\t'.join((('%%+%ds' % l) % s) for l, s in zip(lengths, row)))
@ -3905,7 +3906,6 @@ def CMDcreds_check(parser, args):
checker = _GitCookiesChecker()
checker.ensure_configured_gitcookies()
print('Your .gitcookies have credentials for these hosts:')
checker.print_current_creds()
if not checker.find_and_report_problems():

@ -3135,6 +3135,7 @@ class TestGitCl(unittest.TestCase):
CookiesAuthenticatorMock).start()
git_cl._GitCookiesChecker().print_current_creds()
self.assertEqual(list(sys.stdout.getvalue().splitlines()), [
'Your .gitcookies have credentials for these hosts:',
' Host\tUser\t Which file',
'============================\t====\t===========',
'host-review.googlesource.com\tuser\t.gitcookies',
@ -3144,6 +3145,7 @@ class TestGitCl(unittest.TestCase):
sys.stdout.truncate(0)
git_cl._GitCookiesChecker().print_current_creds()
self.assertEqual(list(sys.stdout.getvalue().splitlines()), [
'Your .gitcookies have credentials for these hosts:',
' Host\tUser\t Which file',
'============================\t====\t===========',
'host-review.googlesource.com\tuser\t.gitcookies',

Loading…
Cancel
Save