Commit e827b0f7 authored by Josip's avatar Josip Committed by LUCI CQ

Adds support to edit description on git cl upload

git cl upload gets a new flag --edit-description, which allows user to
edit git commit message. It only works when updating existing CL.

Bug: 739928
Change-Id: Ia501dc31f32e1887a937d5df39aed03745376827
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2020591Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@google.com>
Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
parent 1a0daf72
......@@ -2406,6 +2406,13 @@ class Changelist(object):
else:
title = ask_for_data(
'Title for patchset [%s]: ' % default_title) or default_title
# User requested to change description
if options.edit_description:
change_desc = ChangeDescription(message, bug=bug, fixed=fixed)
change_desc.prompt()
message = change_desc.description
change_id = self._GetChangeDetail()['change_id']
while True:
footer_change_ids = git_footers.get_footer_change_id(message)
......@@ -4473,6 +4480,10 @@ def CMDupload(parser, args):
'fixed (pre-populates "Fixed:" tag). Same format as '
'-b option / "Bug:" tag. If fixing several issues, '
'separate with commas.')
parser.add_option('--edit-description', action='store_true', default=False,
help='Modify description before upload. Cannot be used '
'with --force. It is a noop when --no-squash is set '
'or a new commit is created.')
orig_args = args
_add_codereview_select_options(parser)
......@@ -4485,6 +4496,9 @@ def CMDupload(parser, args):
options.tbrs = cleanup_list(options.tbrs)
options.cc = cleanup_list(options.cc)
if options.edit_description and options.force:
parser.error('Only one of --force and --edit-description allowed')
if options.message_file:
if options.message:
parser.error('Only one of --message and --message-file allowed.')
......
......@@ -917,7 +917,7 @@ class TestGitCl(TestCase):
short_hostname='chromium',
labels=None, change_id=None, original_title=None,
final_description=None, gitcookies_exists=True,
force=False):
force=False, edit_description=None):
if post_amend_description is None:
post_amend_description = description
cc = cc or []
......@@ -983,6 +983,13 @@ class TestGitCl(TestCase):
((['git', 'config', 'core.editor'],), ''),
((['RunEditor'],), description),
]
# user wants to edit description
if edit_description:
calls += [
((['git', 'config', 'rietveld.bug-prefix'],), ''),
((['git', 'config', 'core.editor'],), ''),
((['RunEditor'],), edit_description),
]
ref_to_push = 'abcdef0123456789'
calls += [
((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'),
......@@ -1240,6 +1247,7 @@ class TestGitCl(TestCase):
final_description=None,
gitcookies_exists=True,
force=False,
edit_description=None,
fetched_description=None):
"""Generic gerrit upload test framework."""
if squash_mode is None:
......@@ -1311,7 +1319,8 @@ class TestGitCl(TestCase):
original_title=original_title,
final_description=final_description,
gitcookies_exists=gitcookies_exists,
force=force)
force=force,
edit_description=edit_description)
# Uncomment when debugging.
# print('\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))))
git_cl.main(['upload'] + upload_args)
......@@ -1531,6 +1540,21 @@ class TestGitCl(TestCase):
'Uploading may fail due to lack of permissions',
git_cl.sys.stdout.getvalue())
def test_upload_change_description_editor(self):
fetched_description = 'foo\n\nChange-Id: 123456789'
description = 'bar\n\nChange-Id: 123456789'
self._run_gerrit_upload_test(
['--squash', '--edit-description'],
description,
[],
fetched_description=fetched_description,
squash=True,
expected_upstream_ref='origin/master',
issue=123456,
change_id='123456789',
original_title='User input',
edit_description=description)
def test_upload_branch_deps(self):
self.mock(git_cl.sys, 'stdout', StringIO())
def mock_run_git(*args, **_kwargs):
......
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