Commit cf6269b4 authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

[git-cl] Handle non-HTTPS repositories gracefully in EnsureAuthenticated

There are some Google-internal repos that use a custom scheme. Having
any remotes pointing to these URLs breaks git cl archive.

Change-Id: Ibd686c5cd11e090f0821ff2b412540138252dfce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1614946
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Auto-Submit: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
parent a7a23c07
......@@ -2010,6 +2010,11 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
if not isinstance(cookie_auth, gerrit_util.CookiesAuthenticator):
return
if urlparse.urlparse(self.GetRemoteUrl()).scheme != 'https':
print('WARNING: Ignoring branch %s with non-https remote %s' %
(self._changelist.branch, self.GetRemoteUrl()))
return
# Lazy-loader to identify Gerrit and Git hosts.
self.GetCodereviewServer()
git_host = self._GetGitHost()
......@@ -2530,7 +2535,7 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
])
traces_to_delete = traces[:-MAX_TRACES]
for trace in traces_to_delete:
os.remove(trace)
os.remove(trace)
except OSError:
print('WARNING: Failed to remove old git traces from\n'
' %s'
......
......@@ -806,16 +806,16 @@ class TestGitCl(TestCase):
return [((cmd, ), 'true')]
calls = [((cmd, ), CERR1)]
if issue:
calls.extend([
((['git', 'config', 'branch.master.gerritserver'],), CERR1),
])
calls.extend([
((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'),
((['git', 'config', 'branch.master.remote'],), 'origin'),
((['git', 'config', 'remote.origin.url'],),
'https://%s.googlesource.com/my/repo' % short_hostname),
])
if issue:
calls.extend([
((['git', 'config', 'branch.master.gerritserver'],), CERR1),
])
return calls
@classmethod
......@@ -2007,6 +2007,22 @@ class TestGitCl(TestCase):
'chromium.googlesource.com')
self.assertTrue('Bearer' in header)
def test_gerrit_ensure_authenticated_non_https(self):
self.calls = [
((['git', 'config', '--bool',
'gerrit.skip-ensure-authenticated'],), CERR1),
((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'),
((['git', 'config', 'branch.master.remote'],), 'origin'),
((['git', 'config', 'remote.origin.url'],), 'custom-scheme://repo'),
]
self.mock(git_cl.gerrit_util, 'CookiesAuthenticator',
CookiesAuthenticatorMockFactory(hosts_with_creds={}))
cl = git_cl.Changelist(codereview='gerrit')
cl.branch = 'master'
cl.branchref = 'refs/heads/master'
cl.lookedup_issue = True
self.assertIsNone(cl.EnsureAuthenticated(force=False))
def _cmd_set_commit_gerrit_common(self, vote, notify=None):
self.mock(git_cl.gerrit_util, 'SetReview',
lambda h, i, labels, notify=None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment