Commit eefe8326 authored by tandrii's avatar tandrii Committed by Commit bot

Gerrit git cl upload: auto-filter patchset titles.

Without it, upload fails because ref is invalid.

BUG=622062
R=andybons@chromium.org

Review-Url: https://codereview.chromium.org/2252043002
parent 54d29546
......@@ -2517,10 +2517,14 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
# https://gerrit-review.googlesource.com/Documentation/user-upload.html
refspec_opts = []
if options.title:
if not re.match(r'^[\w ]+$', options.title):
options.title = re.sub(r'[^\w ]', '', options.title)
print('WARNING: Patchset title may only contain alphanumeric chars '
'and spaces. Cleaned up title:\n%s' % options.title)
if not options.force:
ask_for_data('Press enter to continue, Ctrl+C to abort')
# 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(' ', '_'))
if options.send_mail:
......
......@@ -974,13 +974,18 @@ class TestGitCl(TestCase):
squash=False,
squash_mode='override_nosquash')
def test_gerrit_patch_title(self):
def test_gerrit_patch_bad_chars(self):
self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
self._run_gerrit_upload_test(
['-t', 'Don\'t put under_scores as they become spaces'],
['-f', '-t', 'Don\'t put bad cha,.rs'],
'desc\n\nBUG=\n\nChange-Id: I123456789',
squash=False,
squash_mode='override_nosquash',
ref_suffix='%m=Don\'t_put_under_scores_as_they_become_spaces')
ref_suffix='%m=Dont_put_bad_chars')
self.assertIn(
'WARNING: Patchset title may only contain alphanumeric chars '
'and spaces. Cleaned up title:\nDont put bad chars\n',
git_cl.sys.stdout.getvalue())
def test_gerrit_reviewers_cmd_line(self):
self._run_gerrit_upload_test(
......
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