[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 <iannucci@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
changes/89/5723089/5
Allen Li 1 year ago committed by LUCI CQ
parent 4986d4a74b
commit ead6e4d2fc

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

Loading…
Cancel
Save