From dd8cc1ce969c4104403c48d8d11a8954cc3bf990 Mon Sep 17 00:00:00 2001 From: Allen Li Date: Wed, 10 Jul 2024 21:37:20 +0000 Subject: [PATCH] [git_cl] Extract use_sso as an argument Potentially makes it easier to test (needs more deps extracted and injected though). Change-Id: I3a300264f85f4420d8b41a7cd1155e38341638f5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5689683 Reviewed-by: Yiwei Zhang Commit-Queue: Allen Li --- git_cl.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/git_cl.py b/git_cl.py index d89b27cf7..4c97cdafe 100755 --- a/git_cl.py +++ b/git_cl.py @@ -3678,6 +3678,7 @@ class GitAuthConfigChanger(object): *, host_shortname: str, remote_url: str, + use_sso: bool, ): """Create a new GitAuthConfigChanger. @@ -3685,14 +3686,14 @@ class GitAuthConfigChanger(object): host_shortname: Gerrit host shortname, e.g., chromium remote_url: Git repository's remote URL, e.g., https://chromium.googlesource.com/chromium/tools/depot_tools.git + use_sso: whether to configure auth for SSO """ self._shortname: str = host_shortname parts: urllib.parse.SplitResult = urllib.parse.urlsplit(remote_url) # Base URL looks like https://chromium.googlesource.com/ self._base_url: str = parts._replace(path='/', query='', fragment='').geturl() - - self._should_use_sso: bool = gerrit_util.ShouldUseSSO(gerrit_host) + self._use_sso: bool = use_sso @classmethod def infer_and_create(cls) -> 'GitAuthConfigChanger': @@ -3710,6 +3711,7 @@ class GitAuthConfigChanger(object): return cls( host_shortname=host_shortname, remote_url=remote_url, + use_sso=gerrit_util.ShouldUseSSO(gerrit_host), ) def apply(self): @@ -3725,7 +3727,7 @@ class GitAuthConfigChanger(object): def _apply_cred_helper(self): """Apply config changes relating to credential helper.""" cwd: str = os.getcwd() - if self._should_use_sso: + if self._use_sso: scm.GIT.SetConfig(cwd, f'credential.{self._base_url}.helper', None, @@ -3744,7 +3746,7 @@ class GitAuthConfigChanger(object): """Apply config changes relating to SSO.""" cwd: str = os.getcwd() # SSO - if self._should_use_sso: + if self._use_sso: scm.GIT.SetConfig(cwd, 'protocol.sso.allow', 'always') scm.GIT.SetConfig(cwd, f'url.sso://{self._shortname}/.insteadOf',