From 370d588239e04877773168aa5b4cbacf2740295b Mon Sep 17 00:00:00 2001 From: Allen Li Date: Mon, 29 Jul 2024 22:58:06 +0000 Subject: [PATCH] [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 Reviewed-by: Yiwei Zhang Commit-Queue: Allen Li --- git_cl.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/git_cl.py b/git_cl.py index d80cf13b94..1dd6399beb 100755 --- a/git_cl.py +++ b/git_cl.py @@ -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()