From f5b53c0e98a814aa8d026b07288211a5e4421000 Mon Sep 17 00:00:00 2001
From: Allen Li
Date: Tue, 8 Apr 2025 15:16:09 -0700
Subject: [PATCH] [git_cl] Add --global to creds-check
The UX of cd'ing to a non-Gerrit repo to setup common repo auth is not
good. Also people don't read.
Bug: 408501013
Change-Id: Ia31914cf8672d0b5a6033de11c928140fd34a95c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6442235
Reviewed-by: Gavin Mak
Commit-Queue: Allen Li
---
git_auth.py | 28 +++++++++++++++++++---------
git_cl.py | 9 +++++++--
man/html/depot_tools_tutorial.html | 8 ++++----
man/man7/depot_tools_tutorial.7 | 10 +++++-----
man/src/depot_tools_tutorial.txt | 4 ++--
5 files changed, 37 insertions(+), 22 deletions(-)
diff --git a/git_auth.py b/git_auth.py
index 3a916337a..542542a84 100644
--- a/git_auth.py
+++ b/git_auth.py
@@ -463,11 +463,11 @@ class ConfigWizard(object):
self._ui = ui
self._user_actions = []
- def run(self, remote_url: str):
+ def run(self, *, remote_url: str, force_global: bool):
with self._handle_config_errors():
- self._run(remote_url)
+ self._run(remote_url=remote_url, force_global=force_global)
- def _run(self, remote_url: str):
+ def _run(self, *, remote_url: str, force_global: bool):
self._println('This tool will help check your Gerrit authentication.')
self._println(
'(Report any issues to https://issues.chromium.org/issues/new?component=1456702&template=2076315)'
@@ -481,12 +481,21 @@ class ConfigWizard(object):
self._set_config('protocol.sso.allow', 'always', scope='global')
self._println()
if _is_gerrit_url(remote_url):
- self._println(
- 'Looks like we are running inside a Gerrit repository,')
- self._println(
- f'so we will check your Git configuration for {remote_url}')
- parts = urllib.parse.urlsplit(remote_url)
- self._run_inside_repo(parts)
+ if force_global:
+ self._println(
+ 'We will pretend to be running outside of a Gerrit repository'
+ )
+ self._println(
+ 'and check your global Git configuration since you passed --global.'
+ )
+ self._run_outside_repo()
+ else:
+ self._println(
+ 'Looks like we are running inside a Gerrit repository,')
+ self._println(
+ f'so we will check your Git configuration for {remote_url}')
+ parts = urllib.parse.urlsplit(remote_url)
+ self._run_inside_repo(parts)
else:
self._println(
'Looks like we are running outside of a Gerrit repository,')
@@ -703,6 +712,7 @@ class ConfigWizard(object):
if email:
self._println(f'Your global Git email is: {email}')
return email
+ self._println()
self._println(
'You do not have an email configured in your global Git config.')
if not self._read_yn('Do you want to set one now?', default=True):
diff --git a/git_cl.py b/git_cl.py
index 006f0360d..e7718b004 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -3900,7 +3900,12 @@ class _GitCookiesChecker(object):
@metrics.collector.collect_metrics('git cl creds-check')
def CMDcreds_check(parser, args):
"""Checks credentials and suggests changes."""
- _, _ = parser.parse_args(args)
+ parser.add_option(
+ '--global',
+ action='store_true',
+ dest='force_global',
+ help='Check global credentials instead of for the current repo.')
+ options, args = parser.parse_args(args)
if newauth.SwitchedOn():
cl = Changelist()
@@ -3910,7 +3915,7 @@ def CMDcreds_check(parser, args):
remote_url = ''
wizard = git_auth.ConfigWizard(
git_auth.UserInterface(sys.stdin, sys.stdout))
- wizard.run(remote_url)
+ wizard.run(remote_url=remote_url, force_global=options.force_global)
return 0
if newauth.ExplicitlyDisabled():
git_auth.ClearRepoConfig(os.getcwd(), Changelist())
diff --git a/man/html/depot_tools_tutorial.html b/man/html/depot_tools_tutorial.html
index 3cad3baed..7ea45244e 100644
--- a/man/html/depot_tools_tutorial.html
+++ b/man/html/depot_tools_tutorial.html
@@ -1004,10 +1004,10 @@ commands:
GETTING THE CODE
Unless you plan on only fetching code anonymously, you’ll need to set
-up your auth config in Git. Run this in your home directory:
+up your auth config in Git. Run this:
-
$ git cl creds-check
+
$ git cl creds-check --global
Pick an empty directory and run one of the following:
@@ -1465,7 +1465,7 @@ EOF
$ git map
*
d2902efc4d (HEAD -> chap3) 2014-04-10 ~ beginning of chapter 3
*
d4a945118e (chap2) 2014-04-10 ~ Finish chapter 2
-*
59cdb7335b (origin/master, origin/HEAD, fix_typo) 2014-04-10 ~ Refactor data interchange format. <(
fix_typo, chap2)
+*
59cdb7335b (origin/master, origin/HEAD, fix_typo) 2014-04-10 ~ Refactor data interchange format. <(
chap2, fix_typo)
*
34676a3583 2014-04-10 ~ Ensure FS is exited for all not-in-same-page navigations.
*
7d4784e867 2014-04-10 ~ Add best chapter2 ever!
*
5d26fec369 2014-04-10 ~ Finish chapter 2
@@ -1627,7 +1627,7 @@ by checking out the