diff --git a/git_cl.py b/git_cl.py index 8c58f1428..f7f84d8b0 100755 --- a/git_cl.py +++ b/git_cl.py @@ -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' diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index a665aa9bd..a19181c97 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -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: