From 30ae637731b459f3849867c43a0226d57d25133e Mon Sep 17 00:00:00 2001 From: Alex Turner Date: Tue, 4 Jan 2022 02:32:52 +0000 Subject: [PATCH] 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/+/2983443 Reviewed-by: Edward Lesmes Reviewed-by: Josip Sokcevic Commit-Queue: Alex Turner --- git_cl.py | 9 +++++++-- tests/git_cl_test.py | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/git_cl.py b/git_cl.py index 3540382b0..22c158532 100755 --- a/git_cl.py +++ b/git_cl.py @@ -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/+/[/[patchset]] # But old GWT UI is https://domain/#/c/project/+/[/[patchset]] # Short urls like https://domain/ can be used, but don't allow diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index a88c5e3a2..7be4ebc3c 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -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):