From 0e3589eaf822ae60f8804ae43a94daaaa42e9f5b Mon Sep 17 00:00:00 2001 From: Aravind Vasudevan Date: Thu, 25 May 2023 23:00:30 +0000 Subject: [PATCH] Fix skip-ensure-authenticated config https://crbug.com/603378#c4 introduces gerrit.skipEnsureAuthenticated as simple workaround to allow git_cl work with `sso://` URLs. However, git_cl still warns users to not use `sso://` and all the gerrit API calls break. This change is a fix quick to allow git_cl to work with `sso://` when gerrit.skipEnsureAuthenticated is set to true in .git/config. The authentication check will be fixed to support `sso://` is a follow-up change. Bug: 1431292 Change-Id: Iefc43d205ac3b7fb67b32092567fd13eded205a5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4404933 Reviewed-by: Josip Sokcevic Commit-Queue: Aravind Vasudevan --- git_cl.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/git_cl.py b/git_cl.py index 1e94fa5de..727aa689f 100755 --- a/git_cl.py +++ b/git_cl.py @@ -1913,15 +1913,14 @@ class Changelist(object): def GetGerritHost(self): # Lazy load of configs. self.GetCodereviewServer() + if self._gerrit_host and '.' not in self._gerrit_host: # Abbreviated domain like "chromium" instead of chromium.googlesource.com. - # This happens for internal stuff http://crbug.com/614312. parsed = urllib.parse.urlparse(self.GetRemoteUrl()) if parsed.scheme == 'sso': - print('WARNING: using non-https URLs for remote is likely broken\n' - ' Your current remote is: %s' % self.GetRemoteUrl()) self._gerrit_host = '%s.googlesource.com' % self._gerrit_host self._gerrit_server = 'https://%s' % self._gerrit_host + return self._gerrit_host def _GetGitHost(self): @@ -1941,10 +1940,19 @@ class Changelist(object): if self._gerrit_server: self._gerrit_host = urllib.parse.urlparse(self._gerrit_server).netloc if not self._gerrit_server: + url = urllib.parse.urlparse(self.GetRemoteUrl()) + parts = url.netloc.split('.') + # We assume repo to be hosted on Gerrit, and hence Gerrit server # has "-review" suffix for lowest level subdomain. - parts = self._GetGitHost().split('.') parts[0] = parts[0] + '-review' + + if url.scheme == 'sso' and len(parts) == 1: + # sso:// uses abbreivated hosts, eg. sso://chromium instead of + # chromium.googlesource.com. Hence, for code review server, they need + # to be expanded. + parts[0] += '.googlesource.com' + self._gerrit_host = '.'.join(parts) self._gerrit_server = 'https://%s' % self._gerrit_host return self._gerrit_server