diff --git a/git_auth.py b/git_auth.py index 6585e80c0..1c8150356 100644 --- a/git_auth.py +++ b/git_auth.py @@ -55,7 +55,7 @@ class ConfigChanger(object): self.mode: ConfigMode = mode self._remote_url: str = remote_url - self._set_config_func: Callable[..., str] = set_config_func + self._set_config_func: Callable[..., None] = set_config_func @functools.cached_property def _shortname(self) -> str: @@ -84,13 +84,20 @@ class ConfigChanger(object): # This is determined either from the branch or repo config. # # Example: chromium-review.googlesource.com - gerrit_host: str = cl.GetGerritHost() + gerrit_host = cl.GetGerritHost() # This depends on what the user set for their remote. # There are a couple potential variations for the same host+repo. # # Example: # https://chromium.googlesource.com/chromium/tools/depot_tools.git - remote_url: str = cl.GetRemoteUrl() + remote_url = cl.GetRemoteUrl() + + if gerrit_host is None or remote_url is None: + raise Exception( + 'Error Git auth settings inferring from environment:' + f' {gerrit_host=} {remote_url=}') + assert gerrit_host is not None + assert remote_url is not None return cls( mode=cls._infer_mode(cwd, gerrit_host), @@ -102,7 +109,7 @@ class ConfigChanger(object): """Infer default mode to use.""" if not newauth.Enabled(): return ConfigMode.NO_AUTH - email: str = scm.GIT.GetConfig(cwd, 'user.email', default='') + email: str = scm.GIT.GetConfig(cwd, 'user.email') or '' if gerrit_util.ShouldUseSSO(gerrit_host, email): return ConfigMode.NEW_AUTH_SSO return ConfigMode.NEW_AUTH diff --git a/git_cl.py b/git_cl.py index 3f36e7916..945d631b8 100755 --- a/git_cl.py +++ b/git_cl.py @@ -28,6 +28,7 @@ import sys import tempfile import textwrap import time +import urllib.error import urllib.parse import urllib.request import uuid @@ -856,7 +857,7 @@ class Settings(object): '"git cl config".') return self.tree_status_url - def GetViewVCUrl(self): + def GetViewVCUrl(self) -> str: if not self.viewvc_url: self.viewvc_url = self._GetConfig('rietveld.viewvc-url') return self.viewvc_url @@ -2238,7 +2239,7 @@ class Changelist(object): # Still raise exception so that stack trace is printed. raise - def GetGerritHost(self): + def GetGerritHost(self) -> Optional[str]: # Populate self._gerrit_host self.GetCodereviewServer() @@ -2259,7 +2260,7 @@ class Changelist(object): return None return urllib.parse.urlparse(remote_url).netloc - def _GetGerritHostFromRemoteUrl(self): + def _GetGerritHostFromRemoteUrl(self) -> str: url = urllib.parse.urlparse(self.GetRemoteUrl()) parts = url.netloc.split('.') @@ -2275,7 +2276,7 @@ class Changelist(object): return '.'.join(parts) - def GetCodereviewServer(self): + def GetCodereviewServer(self) -> str: if not self._gerrit_server: # If we're on a branch then get the server potentially associated # with that branch.