Commit 1e82867e authored by Andrii Shyshkalov's avatar Andrii Shyshkalov Committed by Commit Bot

git cl: restart using project~number on Gerrit.

This fixes Gerrit project detection based on remote URL,
accounting for potential 'a/' prefix in the URL path component,
which isn't part of the Gerrit project name.

R=ehmaldonado, mmoss

Bug: 876964, 876910
Change-Id: I473ae8c6c9e0f2034b350901abd67db151e0a3d3
Reviewed-on: https://chromium-review.googlesource.com/1187573Reviewed-by: 's avatarMichael Moss <mmoss@chromium.org>
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
parent 6365bc44
......@@ -2412,6 +2412,14 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
project = urlparse.urlparse(remote_url).path.strip('/')
if project.endswith('.git'):
project = project[:-len('.git')]
# *.googlesource.com hosts ensure that Git/Gerrit projects don't start with
# 'a/' prefix, because 'a/' prefix is used to force authentication in
# gitiles/git-over-https protocol. E.g.,
# https://chromium.googlesource.com/a/v8/v8 refers to the same repo/project
# as
# https://chromium.googlesource.com/v8/v8
if project.startswith('a/'):
project = project[len('a/'):]
return project
def _GerritChangeIdentifier(self):
......@@ -2419,10 +2427,8 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
Not to be confused by value of "Change-Id:" footer.
"""
# TODO(tandrii): undo this once a fix is in place for crbug/876964.
# return gerrit_util.ChangeIdentifier(
# self._GetGerritProject(), self.GetIssue())
return str(self.GetIssue())
return gerrit_util.ChangeIdentifier(
self._GetGerritProject(), self.GetIssue())
@classmethod
def IssueConfigKey(cls):
......
......@@ -1327,7 +1327,7 @@ class TestGitCl(TestCase):
if squash:
calls += [
(('AddReviewers',
'chromium-review.googlesource.com', '123456',
'chromium-review.googlesource.com', 'my%2Frepo~123456',
sorted(reviewers),
['joe@example.com', 'chromium-reviews+test-more-cc@chromium.org'] +
cc, notify), ''),
......@@ -1351,7 +1351,7 @@ class TestGitCl(TestCase):
}),
(('SetReview',
'chromium-review.googlesource.com',
'123456',
'my%2Frepo~123456',
'Self-approving for TBR',
{'Code-Review': 2}, None), ''),
]
......@@ -3450,6 +3450,17 @@ class TestGitCl(TestCase):
self.assertEqual(cl.GetRemoteUrl(), url)
self.assertEqual(cl.GetRemoteUrl(), url) # Must be cached.
def test_gerrit_project_detection(self):
self.calls = [
((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', 'config', 'branch.master.merge'],), 'master'),
((['git', 'config', 'branch.master.remote'],), 'origin'),
((['git', 'config', 'remote.origin.url'],),
'https://chromium.googlesource.com/a/my/repo.git/'),
]
cl = git_cl.Changelist(codereview='gerrit', issue=1)
self.assertEqual(cl._GetGerritProject(), 'my/repo')
if __name__ == '__main__':
logging.basicConfig(
......
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