浏览代码

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>
Gavin Mak 1 年之前
父节点
当前提交
ea802a77b7
共有 2 个文件被更改,包括 4 次插入2 次删除
  1. 2 2
      git_cl.py
  2. 2 0
      tests/git_cl_test.py

+ 2 - 2
git_cl.py

@@ -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():

+ 2 - 0
tests/git_cl_test.py

@@ -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',