Commit 30ae6377 authored by Alex Turner's avatar Alex Turner Committed by LUCI CQ

Accept URLs missing schemes in git cl patch

Currently, calling a command like "git cl patch crrev.com/c/1234567"
will fail with "git cl: error: Invalid issue ID or URL." as no scheme is
supplied (i.e. "git cl patch https://crrev.com/c/1234567" is considered
valid).

This cl removes the requirement for supplying a scheme. Instead, the
script attempts to add "https://" where it would've thrown an error
previously. If the resulting string is valid, it is used. Otherwise, an
error will still be thrown.

Bug: 1223200
Change-Id: I24ee4df48b5f5d434f3abe270f5c3e793c347cc8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2983443Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Alex Turner <alexmt@chromium.org>
parent 54c265ea
......@@ -881,10 +881,10 @@ def ParseIssueNumberArgument(arg):
if arg.isdigit():
return _ParsedIssueNumberArgument(issue=int(arg))
if not arg.startswith('http'):
return fail_result
url = gclient_utils.UpgradeToHttps(arg)
if not url.startswith('http'):
return fail_result
for gerrit_url, short_url in _KNOWN_GERRIT_TO_SHORT_URLS.items():
if url.startswith(short_url):
url = gerrit_url + url[len(short_url):]
......@@ -895,6 +895,11 @@ def ParseIssueNumberArgument(arg):
except ValueError:
return fail_result
# If "https://" was automatically added, fail if `arg` looks unlikely to be a
# URL.
if not arg.startswith('http') and '.' not in parsed_url.netloc:
return fail_result
# Gerrit's new UI is https://domain/c/project/+/<issue_number>[/[patchset]]
# But old GWT UI is https://domain/#/c/project/+/<issue_number>[/[patchset]]
# Short urls like https://domain/<issue_number> can be used, but don't allow
......
......@@ -476,6 +476,11 @@ class TestParseIssueURL(unittest.TestCase):
self._test('https://crrev.com/c/2151934', 2151934, None,
'chromium-review.googlesource.com')
def test_missing_scheme(self):
self._test('codereview.source.com/123', 123, None, 'codereview.source.com')
self._test('crrev.com/c/2151934', 2151934, None,
'chromium-review.googlesource.com')
class GitCookiesCheckerTest(unittest.TestCase):
def setUp(self):
......
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