[git_auth] Parametrize cwd and changelist

To prevent import cycles when moving the auth functions to git_auth

Bug: b/351071334
Change-Id: Idfb474b9a738d5db51dcd82ffde5d047cc36af9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5742790
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
changes/90/5742790/6
Allen Li 1 year ago committed by LUCI CQ
parent 9ad0a20472
commit 370d588239

@ -2360,7 +2360,7 @@ class Changelist(object):
logging.debug(
'Automatically configuring Git repo authentication (current version: %r, latest: %r)',
v, latestVer)
ConfigureGitRepoAuth()
ConfigureGitRepoAuth(os.getcwd(), Changelist())
scm.GIT.SetConfig(settings.GetRoot(),
'depot-tools.gitAuthAutoConfigured',
str(latestVer))
@ -3663,7 +3663,7 @@ def DownloadGerritHook(force):
'chmod +x .git/hooks/commit-msg' % src)
def ConfigureGitAuth() -> None:
def ConfigureGitAuth(cwd: str, cl: Changelist) -> None:
"""Configure Git authentication.
This may modify the global Git config and the local repo config as
@ -3672,7 +3672,6 @@ def ConfigureGitAuth() -> None:
logging.debug('Configuring Git authentication...')
logging.debug('Configuring global Git authentication...')
cl = Changelist()
# We want the user's global config.
# We can probably assume the root directory doesn't have any local
@ -3680,7 +3679,6 @@ def ConfigureGitAuth() -> None:
c = git_auth.ConfigChanger.new_from_env('/', cl)
c.apply_global(os.path.expanduser('~'))
cwd = os.getcwd()
c2 = git_auth.ConfigChanger.new_from_env(cwd, cl)
if c2.mode == c.mode:
logging.debug(
@ -3695,19 +3693,17 @@ def ConfigureGitAuth() -> None:
c2.apply(cwd)
def ConfigureGitRepoAuth() -> None:
def ConfigureGitRepoAuth(cwd: str, cl: Changelist) -> None:
"""Configure the current Git repo authentication."""
logging.debug('Configuring current Git repo authentication...')
cwd = os.getcwd()
c = git_auth.ConfigChanger.new_from_env(cwd, Changelist())
c = git_auth.ConfigChanger.new_from_env(cwd, cl)
c.apply(cwd)
def ClearGitRepoAuth() -> None:
def ClearGitRepoAuth(cwd: str, cl: Changelist) -> None:
"""Clear the current Git repo authentication."""
logging.debug('Clearing current Git repo authentication...')
cwd = os.getcwd()
c = git_auth.ConfigChanger.new_from_env(cwd, Changelist())
c = git_auth.ConfigChanger.new_from_env(cwd, cl)
c.mode = git_auth.ConfigMode.NO_AUTH
c.apply(cwd)
@ -3941,10 +3937,10 @@ def CMDcreds_check(parser, args):
_, _ = parser.parse_args(args)
if newauth.Enabled():
ConfigureGitAuth()
ConfigureGitAuth(os.getcwd(), Changelist())
return 0
if newauth.ExplicitlyDisabled():
ClearGitRepoAuth()
ClearGitRepoAuth(os.getcwd(), Changelist())
# Code below checks .gitcookies. Abort if using something else.
auth_name, _ = gerrit_util.debug_auth()

Loading…
Cancel
Save