diff --git a/git_cl.py b/git_cl.py index 46af2bce17..be339c0ef8 100755 --- a/git_cl.py +++ b/git_cl.py @@ -2934,16 +2934,20 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): print('Adding self-LGTM (Code-Review +1) because of TBRs') refspec_opts.append('l=Code-Review+1') - if options.title: - if not re.match(r'^[\w ]+$', options.title): - options.title = re.sub(r'[^\w ]', '', options.title) + title = options.title + if not title: + default = RunGit(['show', '-s', '--format=%s', 'HEAD']).strip() + title = ask_for_data('Title for patchset [%s]: ' % default) or default + if title: + if not re.match(r'^[\w ]+$', title): + title = re.sub(r'[^\w ]', '', title) print('WARNING: Patchset title may only contain alphanumeric chars ' - 'and spaces. Cleaned up title:\n%s' % options.title) + 'and spaces. Cleaned up title:\n%s' % 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. - refspec_opts.append('m=' + options.title.replace(' ', '_')) + refspec_opts.append('m=' + title.replace(' ', '_')) if options.send_mail: if not change_desc.get_reviewers(): diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index d68129daef..81540a9d33 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -1338,7 +1338,7 @@ class TestGitCl(TestCase): def _gerrit_upload_calls(cls, description, reviewers, squash, squash_mode='default', expected_upstream_ref='origin/refs/heads/master', - ref_suffix='', notify=False, + ref_suffix='', title=None, notify=False, post_amend_description=None, issue=None, cc=None): if post_amend_description is None: post_amend_description = description @@ -1409,6 +1409,18 @@ class TestGitCl(TestCase): expected_upstream_ref + '..' + ref_to_push],), ''), ] + + if not title: + calls += [ + ((['git', 'show', '-s', '--format=%s', 'HEAD'],), ''), + (('Title for patchset []: ',), ''), + ] + else: + if ref_suffix: + ref_suffix += ',m=' + title + else: + ref_suffix = '%m=' + title + notify_suffix = 'notify=%s' % ('ALL' if notify else 'NONE') if ref_suffix: ref_suffix += ',' + notify_suffix @@ -1462,6 +1474,7 @@ class TestGitCl(TestCase): squash_mode=None, expected_upstream_ref='origin/refs/heads/master', ref_suffix='', + title=None, notify=False, post_amend_description=None, issue=None, @@ -1494,7 +1507,7 @@ class TestGitCl(TestCase): description, reviewers, squash, squash_mode=squash_mode, expected_upstream_ref=expected_upstream_ref, - ref_suffix=ref_suffix, notify=notify, + ref_suffix=ref_suffix, title=title, notify=notify, post_amend_description=post_amend_description, issue=issue, cc=cc) # Uncomment when debugging. @@ -1534,7 +1547,7 @@ class TestGitCl(TestCase): 'desc\n\nBUG=\n\nChange-Id: I123456789', squash=False, squash_mode='override_nosquash', - ref_suffix='%m=Dont_put_bad_chars') + title='Dont_put_bad_chars') self.assertIn( 'WARNING: Patchset title may only contain alphanumeric chars ' 'and spaces. Cleaned up title:\nDont put bad chars\n',