Commit bf766ba3 authored by tandrii@chromium.org's avatar tandrii@chromium.org

Gerrit git cl upload: implement patchset title (message).

R=machenbach@chromium.org,andybons@chromium.org
BUG=579178

Review URL: https://codereview.chromium.org/1886433003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@299886 0039d316-1c4b-4281-b951-d872f2087c98
parent 11a899e0
...@@ -2235,11 +2235,6 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): ...@@ -2235,11 +2235,6 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
branch = GetTargetRef(remote, remote_branch, options.target_branch, branch = GetTargetRef(remote, remote_branch, options.target_branch,
pending_prefix='') pending_prefix='')
if options.title:
# TODO(tandrii): it's now supported by Gerrit, implement!
print "\nPatch titles (-t) are not supported in Gerrit. Aborting..."
return 1
if options.squash: if options.squash:
if not self.GetIssue(): if not self.GetIssue():
# TODO(tandrii): deperecate this after 2016Q2. Backwards compatibility # TODO(tandrii): deperecate this after 2016Q2. Backwards compatibility
...@@ -2387,6 +2382,16 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): ...@@ -2387,6 +2382,16 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
change_desc.update_reviewers(options.reviewers, options.tbr_owners, change_desc.update_reviewers(options.reviewers, options.tbr_owners,
change) change)
# Extra options that can be specified at push time. Doc:
# https://gerrit-review.googlesource.com/Documentation/user-upload.html
refspec_opts = []
if options.title:
# Per doc, spaces must be converted to underscores, and Gerrit will do the
# reverse on its side.
if '_' in options.title:
print('WARNING: underscores in title will be converted to spaces.')
refspec_opts.append('m=' + options.title.replace(' ', '_'))
receive_options = [] receive_options = []
cc = self.GetCCList().split(',') cc = self.GetCCList().split(',')
if options.cc: if options.cc:
...@@ -2398,13 +2403,24 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): ...@@ -2398,13 +2403,24 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
receive_options.extend( receive_options.extend(
'--reviewer=' + email for email in change_desc.get_reviewers()) '--reviewer=' + email for email in change_desc.get_reviewers())
git_command = ['push'] git_command = ['git', 'push']
if receive_options: if receive_options:
# TODO(tandrii): clean this up in follow up. This doesn't work, as it gets
# totally ignored by Gerrit.
git_command.append('--receive-pack=git receive-pack %s' % git_command.append('--receive-pack=git receive-pack %s' %
' '.join(receive_options)) ' '.join(receive_options))
git_command += [gerrit_remote, ref_to_push + ':refs/for/' + branch]
refspec_suffix = ''
if refspec_opts:
refspec_suffix = '%' + ','.join(refspec_opts)
assert ' ' not in refspec_suffix, (
'spaces not allowed in refspec: "%s"' % refspec_suffix)
refspec = '%s:refs/for/%s%s' % (ref_to_push, branch, refspec_suffix)
git_command += [gerrit_remote, refspec]
push_stdout = gclient_utils.CheckCallAndFilter( push_stdout = gclient_utils.CheckCallAndFilter(
['git'] + git_command, git_command,
print_stdout=True, print_stdout=True,
# Flush after every line: useful for seeing progress when running as # Flush after every line: useful for seeing progress when running as
# recipe. # recipe.
......
...@@ -738,6 +738,7 @@ class TestGitCl(TestCase): ...@@ -738,6 +738,7 @@ class TestGitCl(TestCase):
@classmethod @classmethod
def _gerrit_upload_calls(cls, description, reviewers, squash, def _gerrit_upload_calls(cls, description, reviewers, squash,
expected_upstream_ref='origin/refs/heads/master', expected_upstream_ref='origin/refs/heads/master',
ref_suffix='',
post_amend_description=None, issue=None): post_amend_description=None, issue=None):
if post_amend_description is None: if post_amend_description is None:
post_amend_description = description post_amend_description = description
...@@ -810,7 +811,7 @@ class TestGitCl(TestCase): ...@@ -810,7 +811,7 @@ class TestGitCl(TestCase):
calls += [ calls += [
((['git', ((['git',
'push', receive_pack, 'origin', 'push', receive_pack, 'origin',
ref_to_push + ':refs/for/refs/heads/master'],), ref_to_push + ':refs/for/refs/heads/master' + ref_suffix],),
('remote:\n' ('remote:\n'
'remote: Processing changes: (\)\n' 'remote: Processing changes: (\)\n'
'remote: Processing changes: (|)\n' 'remote: Processing changes: (|)\n'
...@@ -840,18 +841,21 @@ class TestGitCl(TestCase): ...@@ -840,18 +841,21 @@ class TestGitCl(TestCase):
self, self,
upload_args, upload_args,
description, description,
reviewers, reviewers=None,
squash=False, squash=False,
expected_upstream_ref='origin/refs/heads/master', expected_upstream_ref='origin/refs/heads/master',
ref_suffix='',
post_amend_description=None, post_amend_description=None,
issue=None): issue=None):
"""Generic gerrit upload test framework.""" """Generic gerrit upload test framework."""
reviewers = reviewers or []
self.mock(git_cl.gerrit_util, "CookiesAuthenticator", self.mock(git_cl.gerrit_util, "CookiesAuthenticator",
CookiesAuthenticatorMockFactory(same_cookie='same_cred')) CookiesAuthenticatorMockFactory(same_cookie='same_cred'))
self.calls = self._gerrit_base_calls(issue=issue) self.calls = self._gerrit_base_calls(issue=issue)
self.calls += self._gerrit_upload_calls( self.calls += self._gerrit_upload_calls(
description, reviewers, squash, description, reviewers, squash,
expected_upstream_ref=expected_upstream_ref, expected_upstream_ref=expected_upstream_ref,
ref_suffix=ref_suffix,
post_amend_description=post_amend_description, post_amend_description=post_amend_description,
issue=issue) issue=issue)
# Uncomment when debugging. # Uncomment when debugging.
...@@ -872,6 +876,12 @@ class TestGitCl(TestCase): ...@@ -872,6 +876,12 @@ class TestGitCl(TestCase):
'desc\n\nBUG=\n\nChange-Id: I123456789\n', 'desc\n\nBUG=\n\nChange-Id: I123456789\n',
[]) [])
def test_gerrit_patch_title(self):
self._run_gerrit_upload_test(
['-t', 'Don\'t put under_scores as they become spaces'],
'desc\n\nBUG=\n\nChange-Id: I123456789',
ref_suffix='%m=Don\'t_put_under_scores_as_they_become_spaces')
def test_gerrit_reviewers_cmd_line(self): def test_gerrit_reviewers_cmd_line(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
['-r', 'foo@example.com'], ['-r', 'foo@example.com'],
......
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