From ead6e4d2fc293a9c1c1c6553b4dedf97496b84f7 Mon Sep 17 00:00:00 2001 From: Allen Li Date: Sat, 20 Jul 2024 00:46:53 +0000 Subject: [PATCH] [git_cl] Parametrize cwd in new_from_env We need to be able to do this from different dirs later. Bug: b/351071334 Change-Id: I18dd2c71ea52d79a56ccaee88a12be97465b9d2a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5723089 Reviewed-by: Robbie Iannucci Commit-Queue: Allen Li Reviewed-by: Yiwei Zhang --- git_cl.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/git_cl.py b/git_cl.py index c2426725e..cdb3cd22a 100755 --- a/git_cl.py +++ b/git_cl.py @@ -3672,15 +3672,17 @@ def DownloadGerritHook(force): def ConfigureGitRepoAuth() -> None: """Configure the current Git repo authentication.""" logging.debug('Configuring current Git repo authentication...') - GitAuthConfigChanger.new_from_env().apply(os.getcwd()) + cwd = os.getcwd() + c = GitAuthConfigChanger.new_from_env(cwd) + c.apply(cwd) def ClearGitRepoAuth() -> None: """Clear the current Git repo authentication.""" logging.debug('Clearing current Git repo authentication...') - c = GitAuthConfigChanger.new_from_env() + c = GitAuthConfigChanger.new_from_env(cwd) c.mode = GitConfigMode.OLD_AUTH - c.apply(os.getcwd()) + c.apply(cwd) class GitConfigMode(enum.Enum): @@ -3738,7 +3740,7 @@ class GitAuthConfigChanger(object): return parts._replace(path='/', query='', fragment='').geturl() @classmethod - def new_from_env(cls) -> 'GitAuthConfigChanger': + def new_from_env(cls, cwd: str) -> 'GitAuthConfigChanger': """Create a GitAuthConfigChanger by inferring from env.""" cl = Changelist() # chromium-review.googlesource.com @@ -3748,7 +3750,7 @@ class GitAuthConfigChanger(object): remote_url: str = cl.GetRemoteUrl() return cls( - mode=cls._infer_mode(os.getcwd(), gerrit_host), + mode=cls._infer_mode(cwd, gerrit_host), remote_url=remote_url, )