[git_auth] Rename GitAuthConfigChanger

Bug: b/351071334
Change-Id: Ia12bf72bfaef11768cb60ba0631aafd5ffc9f1fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5739676
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
changes/76/5739676/5
Allen Li 1 year ago committed by LUCI CQ
parent fed7aa526c
commit 8dde9800ee

@ -14,13 +14,13 @@ import scm
class ConfigMode(enum.Enum): class ConfigMode(enum.Enum):
"""Modes to pass to GitAuthConfigChanger""" """Modes to pass to ConfigChanger"""
NO_AUTH = 1 NO_AUTH = 1
NEW_AUTH = 2 NEW_AUTH = 2
NEW_AUTH_SSO = 3 NEW_AUTH_SSO = 3
class GitAuthConfigChanger(object): class ConfigChanger(object):
"""Changes Git auth config as needed for Gerrit.""" """Changes Git auth config as needed for Gerrit."""
# Can be used to determine whether this version of the config has # Can be used to determine whether this version of the config has
@ -37,7 +37,7 @@ class GitAuthConfigChanger(object):
remote_url: str, remote_url: str,
set_config_func: Callable[..., None] = scm.GIT.SetConfig, set_config_func: Callable[..., None] = scm.GIT.SetConfig,
): ):
"""Create a new GitAuthConfigChanger. """Create a new ConfigChanger.
Args: Args:
mode: How to configure auth mode: How to configure auth
@ -68,8 +68,8 @@ class GitAuthConfigChanger(object):
return parts._replace(path='/', query='', fragment='').geturl() return parts._replace(path='/', query='', fragment='').geturl()
@classmethod @classmethod
def new_from_env(cls, cwd: str) -> 'GitAuthConfigChanger': def new_from_env(cls, cwd: str) -> 'ConfigChanger':
"""Create a GitAuthConfigChanger by inferring from env. """Create a ConfigChanger by inferring from env.
The Gerrit host is inferred from the current repo/branch. The Gerrit host is inferred from the current repo/branch.
The user, which is used to determine the mode, is inferred using The user, which is used to determine the mode, is inferred using

@ -2346,7 +2346,7 @@ class Changelist(object):
return return
if newauth.Enabled(): if newauth.Enabled():
latestVer: int = git_auth.GitAuthConfigChanger.VERSION latestVer: int = git_auth.ConfigChanger.VERSION
v: int = 0 v: int = 0
try: try:
v = int( v = int(
@ -3674,11 +3674,11 @@ def ConfigureGitAuth() -> None:
# We want the user's global config. # We want the user's global config.
# We can probably assume the root directory doesn't have any local # We can probably assume the root directory doesn't have any local
# Git configuration. # Git configuration.
c = git_auth.GitAuthConfigChanger.new_from_env('/') c = git_auth.ConfigChanger.new_from_env('/')
c.apply_global(os.path.expanduser('~')) c.apply_global(os.path.expanduser('~'))
cwd = os.getcwd() cwd = os.getcwd()
c2 = git_auth.GitAuthConfigChanger.new_from_env(cwd) c2 = git_auth.ConfigChanger.new_from_env(cwd)
if c2.mode == c.mode: if c2.mode == c.mode:
logging.debug( logging.debug(
'Local user wants same mode %s as global; clearing local repo auth config', 'Local user wants same mode %s as global; clearing local repo auth config',
@ -3696,14 +3696,14 @@ def ConfigureGitRepoAuth() -> None:
"""Configure the current Git repo authentication.""" """Configure the current Git repo authentication."""
logging.debug('Configuring current Git repo authentication...') logging.debug('Configuring current Git repo authentication...')
cwd = os.getcwd() cwd = os.getcwd()
c = git_auth.GitAuthConfigChanger.new_from_env(cwd) c = git_auth.ConfigChanger.new_from_env(cwd)
c.apply(cwd) c.apply(cwd)
def ClearGitRepoAuth() -> None: def ClearGitRepoAuth() -> None:
"""Clear the current Git repo authentication.""" """Clear the current Git repo authentication."""
logging.debug('Clearing current Git repo authentication...') logging.debug('Clearing current Git repo authentication...')
c = git_auth.GitAuthConfigChanger.new_from_env(cwd) c = git_auth.ConfigChanger.new_from_env(cwd)
c.mode = git_auth.ConfigMode.NO_AUTH c.mode = git_auth.ConfigMode.NO_AUTH
c.apply(cwd) c.apply(cwd)

Loading…
Cancel
Save