From e827b0f7ec9d54c901ac9a9d2d734cd5ecbf478e Mon Sep 17 00:00:00 2001 From: Josip Date: Thu, 30 Jan 2020 00:07:20 +0000 Subject: [PATCH] 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/+/2020591 Reviewed-by: Andrii Shyshkalov Reviewed-by: Anthony Polito Commit-Queue: Josip Sokcevic --- git_cl.py | 14 ++++++++++++++ tests/git_cl_test.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/git_cl.py b/git_cl.py index b41a5ee88..530fd79eb 100755 --- a/git_cl.py +++ b/git_cl.py @@ -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.') diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index e9d28b54f..d70da9e90 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -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):