Commit b56ad33d authored by Aaron Gable's avatar Aaron Gable Committed by Commit Bot

Respect -t/--title in initial cl uploads to Gerrit

BUG=674254

Change-Id: Icdc572648dfffeca7e28f327e085f64985221ce9
Reviewed-on: https://chromium-review.googlesource.com/425823
Commit-Queue: Aaron Gable <agable@chromium.org>
Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
parent 99790f42
...@@ -2659,6 +2659,9 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): ...@@ -2659,6 +2659,9 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
branch = GetTargetRef(remote, remote_branch, options.target_branch, branch = GetTargetRef(remote, remote_branch, options.target_branch,
pending_prefix_check=False) pending_prefix_check=False)
# This may be None; default fallback value is determined in logic below.
title = options.title
if options.squash: if options.squash:
self._GerritCommitMsgHookCheck(offer_removal=not options.force) self._GerritCommitMsgHookCheck(offer_removal=not options.force)
if self.GetIssue(): if self.GetIssue():
...@@ -2668,6 +2671,10 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): ...@@ -2668,6 +2671,10 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
DieWithError( DieWithError(
'failed to fetch description from current Gerrit change %d\n' 'failed to fetch description from current Gerrit change %d\n'
'%s' % (self.GetIssue(), self.GetIssueURL())) '%s' % (self.GetIssue(), self.GetIssueURL()))
if not title:
default_title = RunGit(['show', '-s', '--format=%s', 'HEAD']).strip()
title = ask_for_data(
'Title for patchset [%s]: ' % default_title) or default_title
change_id = self._GetChangeDetail()['change_id'] change_id = self._GetChangeDetail()['change_id']
while True: while True:
footer_change_ids = git_footers.get_footer_change_id(message) footer_change_ids = git_footers.get_footer_change_id(message)
...@@ -2703,11 +2710,19 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): ...@@ -2703,11 +2710,19 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
# footer. # footer.
assert [change_id] == git_footers.get_footer_change_id(message) assert [change_id] == git_footers.get_footer_change_id(message)
change_desc = ChangeDescription(message) change_desc = ChangeDescription(message)
else: else: # if not self.GetIssue()
change_desc = ChangeDescription( if options.message:
options.message or CreateDescriptionFromLog(args)) message = options.message
else:
message = CreateDescriptionFromLog(args)
if options.title:
message = options.title + '\n\n' + message
change_desc = ChangeDescription(message)
if not options.force: if not options.force:
change_desc.prompt(bug=options.bug) change_desc.prompt(bug=options.bug)
# On first upload, patchset title is always this string, while
# --title flag gets converted to first line of message.
title = 'Initial upload'
if not change_desc.description: if not change_desc.description:
DieWithError("Description is empty. Aborting...") DieWithError("Description is empty. Aborting...")
message = change_desc.description message = change_desc.description
...@@ -2785,14 +2800,6 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): ...@@ -2785,14 +2800,6 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
print('Adding self-LGTM (Code-Review +1) because of TBRs') print('Adding self-LGTM (Code-Review +1) because of TBRs')
refspec_opts.append('l=Code-Review+1') refspec_opts.append('l=Code-Review+1')
title = options.title
if not title:
if self.GetIssue():
# We already have an issue, so we should ask for a title for new patch.
default = RunGit(['show', '-s', '--format=%s', 'HEAD']).strip()
title = ask_for_data('Title for patchset [%s]: ' % default) or default
else:
title = 'Initial upload'
if title: if title:
if not re.match(r'^[\w ]+$', title): if not re.match(r'^[\w ]+$', title):
title = re.sub(r'[^\w ]', '', title) title = re.sub(r'[^\w ]', '', title)
......
...@@ -1262,6 +1262,15 @@ class TestGitCl(TestCase): ...@@ -1262,6 +1262,15 @@ class TestGitCl(TestCase):
((['git', 'log', '--pretty=format:%s\n\n%b', ((['git', 'log', '--pretty=format:%s\n\n%b',
'fake_ancestor_sha..HEAD'],), 'fake_ancestor_sha..HEAD'],),
description)] description)]
if squash:
title = 'Initial_upload'
else:
if not title:
calls += [
((['git', 'show', '-s', '--format=%s', 'HEAD'],), ''),
(('Title for patchset []: ',), 'User input'),
]
title = 'User_input'
if not git_footers.get_footer_change_id(description) and not squash: if not git_footers.get_footer_change_id(description) and not squash:
calls += [ calls += [
# DownloadGerritHook(False) # DownloadGerritHook(False)
...@@ -1307,16 +1316,6 @@ class TestGitCl(TestCase): ...@@ -1307,16 +1316,6 @@ class TestGitCl(TestCase):
expected_upstream_ref + '..' + ref_to_push],), ''), expected_upstream_ref + '..' + ref_to_push],), ''),
] ]
if not title:
if issue:
calls += [
((['git', 'show', '-s', '--format=%s', 'HEAD'],), ''),
(('Title for patchset []: ',), 'User input'),
]
title = 'User_input'
else:
title = 'Initial_upload'
if title: if title:
if ref_suffix: if ref_suffix:
ref_suffix += ',m=' + title ref_suffix += ',m=' + title
......
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