[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 <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
changes/35/6442235/5
Allen Li 3 months ago committed by LUCI CQ
parent 07d24776f2
commit f5b53c0e98

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

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

@ -1004,10 +1004,10 @@ commands:</p></div>
<h2 id="_getting_the_code">GETTING THE CODE</h2>
<div class="sectionbody">
<div class="paragraph"><p>Unless you plan on only fetching code anonymously, you&#8217;ll need to set
up your auth config in Git. Run this in your home directory:</p></div>
up your auth config in Git. Run this:</p></div>
<div class="listingblock">
<div class="content">
<pre><code><strong><span class="white">$ git cl creds-check</span></strong></code></pre>
<pre><code><strong><span class="white">$ git cl creds-check --global</span></strong></code></pre>
</div></div>
<div class="paragraph"><p>Pick an empty directory and run one of the following:</p></div>
<div class="listingblock">
@ -1465,7 +1465,7 @@ EOF
<span style="font-weight: bold; color: #BFBFBF">$ git map</span>
* <span style="color: #FF5555"></span><span style="font-weight: bold; color: #FF5555">d2902efc4d</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span> <span style="color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">(</span><span style="font-weight: bold; color: #8BE9FD"></span><span style="font-weight: bold; color: #8BE9FD">HEAD -&gt; chap3</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span><span style="color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">) </span><span style="font-weight: bold"></span><span style="font-weight: bold"></span><span style="color: #F1FA8C">2014-04-10</span> ~ beginning of chapter 3
* <span style="color: #FF5555"></span><span style="font-weight: bold; color: #FF5555">d4a945118e</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span> <span style="color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">(</span><span style="font-weight: bold; color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">chap2</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span><span style="color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">) </span><span style="font-weight: bold"></span><span style="font-weight: bold"></span><span style="color: #F1FA8C">2014-04-10</span> ~ Finish chapter 2
* <span style="color: #FF5555"></span><span style="font-weight: bold; color: #FF5555">59cdb7335b</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span> <span style="color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">(</span><span style="font-weight: bold; color: #FF5555">origin/master</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span><span style="color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">, </span><span style="font-weight: bold; color: #FF5555">origin/HEAD</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span><span style="color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">, </span><span style="font-weight: bold; color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">fix_typo</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span><span style="color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">) </span><span style="font-weight: bold"></span><span style="font-weight: bold"></span><span style="color: #F1FA8C">2014-04-10</span> ~ Refactor data interchange format. &lt;(<span style="color: #BFBFBF"></span><span style="font-weight: bold; color: #BFBFBF">fix_typo, chap2</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span>)
* <span style="color: #FF5555"></span><span style="font-weight: bold; color: #FF5555">59cdb7335b</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span> <span style="color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">(</span><span style="font-weight: bold; color: #FF5555">origin/master</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span><span style="color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">, </span><span style="font-weight: bold; color: #FF5555">origin/HEAD</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span><span style="color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">, </span><span style="font-weight: bold; color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">fix_typo</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span><span style="color: #50FA7B"></span><span style="font-weight: bold; color: #50FA7B">) </span><span style="font-weight: bold"></span><span style="font-weight: bold"></span><span style="color: #F1FA8C">2014-04-10</span> ~ Refactor data interchange format. &lt;(<span style="color: #BFBFBF"></span><span style="font-weight: bold; color: #BFBFBF">chap2, fix_typo</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span>)
* <span style="color: #FF5555"></span><span style="font-weight: bold; color: #FF5555">34676a3583</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span> <span style="color: #F1FA8C">2014-04-10</span> ~ Ensure FS is exited for all not-in-same-page navigations.
* <span style="color: #FF5555"></span><span style="font-weight: bold; color: #FF5555">7d4784e867</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span> <span style="color: #F1FA8C">2014-04-10</span> ~ Add best chapter2 ever!
* <span style="color: #FF5555"></span><span style="font-weight: bold; color: #FF5555">5d26fec369</span><span style="font-weight: bold"></span><span style="font-weight: bold"></span> <span style="color: #F1FA8C">2014-04-10</span> ~ Finish chapter 2
@ -1627,7 +1627,7 @@ by checking out the <a href="https://chromium.googlesource.com/chromium/tools/de
<div id="footer">
<div id="footer-text">
Last updated
2025-04-04 22:26:10 UTC
2025-04-08 21:53:21 UTC
</div>
</div>
</body>

@ -2,12 +2,12 @@
.\" Title: depot_tools_tutorial
.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\" Date: 04/04/2025
.\" Date: 04/08/2025
.\" Manual: Chromium depot_tools Manual
.\" Source: depot_tools a7d7eadae
.\" Source: depot_tools 82ff119a1
.\" Language: English
.\"
.TH "DEPOT_TOOLS_TUTORIAL" "7" "04/04/2025" "depot_tools a7d7eadae" "Chromium depot_tools Manual"
.TH "DEPOT_TOOLS_TUTORIAL" "7" "04/08/2025" "depot_tools 82ff119a1" "Chromium depot_tools Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@ -286,13 +286,13 @@ If you have never used git before, you\(cqll need to set some global git configu
.sp
.SH "GETTING THE CODE"
.sp
Unless you plan on only fetching code anonymously, you\(cqll need to set up your auth config in Git\&. Run this in your home directory:
Unless you plan on only fetching code anonymously, you\(cqll need to set up your auth config in Git\&. Run this:
.sp
.if n \{\
.RS 4
.\}
.nf
\fB$ git cl creds\-check\fR
\fB$ git cl creds\-check \-\-global\fR
.fi
.if n \{\
.RE

@ -178,11 +178,11 @@ 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:
[subs="quotes"]
----
[white]**$ git cl creds-check**
[white]**$ git cl creds-check --global**
----
Pick an empty directory and run one of the following:

Loading…
Cancel
Save