Commit ae510e8f authored by Florian Mayer's avatar Florian Mayer Committed by LUCI CQ

Do not crash for non URL (i.e. SSH) remotes.

Without this change, having an SSH remote configured makes `git cl
archive` crash:

Traceback (most recent call last):
  File "/usr/local/google/home/fmayer/depot_tools/metrics.py", line 267, in print_notice_and_exit
    yield
  File "/usr/local/google/home/fmayer/depot_tools/git_cl.py", line 5553, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/usr/local/google/home/fmayer/depot_tools/git_cl.py", line 5535, in main
    return dispatcher.execute(OptionParser(), argv)
  File "/usr/local/google/home/fmayer/depot_tools/subcommand.py", line 252, in execute
    return command(parser, args[1:])
  File "/usr/local/google/home/fmayer/depot_tools/metrics.py", line 252, in _inner
    return self._collect_metrics(func, command_name, *args, **kwargs)
  File "/usr/local/google/home/fmayer/depot_tools/metrics.py", line 232, in _collect_metrics
    gclient_utils.reraise(exception[0], exception[1], exception[2])
  File "/usr/local/google/home/fmayer/depot_tools/metrics.py", line 205, in _collect_metrics
    result = func(*args, **kwargs)
  File "/usr/local/google/home/fmayer/depot_tools/git_cl.py", line 3786, in CMDarchive
    for cl, status in statuses
  File "/usr/local/google/home/fmayer/depot_tools/git_cl.py", line 3599, in get_cl_statuses
    cl.EnsureAuthenticated(force=False, refresh=True)
  File "/usr/local/google/home/fmayer/depot_tools/git_cl.py", line 1757, in EnsureAuthenticated
    if urllib.parse.urlparse(self.GetRemoteUrl()).scheme != 'https':
  File "/usr/lib/python2.7/urlparse.py", line 143, in urlparse
    tuple = urlsplit(url, scheme, allow_fragments)
  File "/usr/lib/python2.7/urlparse.py", line 201, in urlsplit
    i = url.find(':')
AttributeError: 'NoneType' object has no attribute 'find'

Change-Id: I6f794f11d3ed5e3dbedfe278ded660fca32abda6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2030505
Commit-Queue: Florian Mayer <fmayer@google.com>
Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
parent 305542ea
......@@ -1754,7 +1754,11 @@ class Changelist(object):
if not isinstance(cookie_auth, gerrit_util.CookiesAuthenticator):
return
if urllib.parse.urlparse(self.GetRemoteUrl()).scheme != 'https':
remote_url = self.GetRemoteUrl()
if remote_url is None:
print('WARNING: invalid remote')
return
if urllib.parse.urlparse(remote_url).scheme != 'https':
print('WARNING: Ignoring branch %s with non-https remote %s' %
(self.branch, self.GetRemoteUrl()))
return
......
......@@ -2103,6 +2103,23 @@ class TestGitCl(TestCase):
cl.lookedup_issue = True
self.assertIsNone(cl.EnsureAuthenticated(force=False))
def test_gerrit_ensure_authenticated_non_url(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'], ),
'git@somehost.example:foo/bar.git'),
]
self.mock(git_cl.gerrit_util, 'CookiesAuthenticator',
CookiesAuthenticatorMockFactory(hosts_with_creds={}))
cl = git_cl.Changelist()
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