[git_auth] Move auto configure logic

Bug: b/351071334
Change-Id: Ic6574f86208b22e406e36f8cd45a564ea74ec7f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5742793
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
changes/93/5742793/17
Allen Li 12 months ago committed by LUCI CQ
parent a6cd7589e9
commit be5ff1a6c4

@ -223,6 +223,31 @@ class ConfigChanger(object):
self._set_config_func(*args, **kwargs)
def AutoConfigure(cwd: str, cl: git_cl.Changelist) -> None:
"""Configure Git authentication automatically.
This tracks when the config that has already been applied and skips
doing anything if so.
This may modify the global Git config and the local repo config as
needed.
"""
latestVer: int = ConfigChanger.VERSION
v: int = 0
try:
v = int(
scm.GIT.GetConfig(cwd, 'depot-tools.gitauthautoconfigured') or '0')
except ValueError:
v = 0
if v < latestVer:
logging.debug(
'Automatically configuring Git repo authentication'
' (current version: %r, latest: %r)', v, latestVer)
ConfigureRepo(cwd, cl)
scm.GIT.SetConfig(cwd, 'depot-tools.gitAuthAutoConfigured',
str(latestVer))
def Configure(cwd: str, cl: git_cl.Changelist) -> None:
"""Configure Git authentication.

@ -2347,23 +2347,7 @@ class Changelist(object):
return
if newauth.Enabled():
latestVer: int = git_auth.ConfigChanger.VERSION
v: int = 0
try:
v = int(
scm.GIT.GetConfig(settings.GetRoot(),
'depot-tools.gitauthautoconfigured',
default='0'))
except ValueError:
v = 0
if v < latestVer:
logging.debug(
'Automatically configuring Git repo authentication (current version: %r, latest: %r)',
v, latestVer)
git_auth.ConfigureRepo(os.getcwd(), Changelist())
scm.GIT.SetConfig(settings.GetRoot(),
'depot-tools.gitAuthAutoConfigured',
str(latestVer))
git_auth.AutoConfigure(os.getcwd(), Changelist())
return
# Lazy-loader to identify Gerrit and Git hosts.

Loading…
Cancel
Save