Commit 68e6cf3c authored by Gavin Mak's avatar Gavin Mak Committed by LUCI CQ

Don't open text editor when using --message-file

When using git cl upload --message-file, the text editor prompts the
user to edit the description. This change suppresses the editor when
a message file is passed in.

Change-Id: Ifa568e155e72eeb49f55ded0ddac1b5a940687af
Bug:916230
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2643781Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
parent f08e425f
......@@ -2251,7 +2251,7 @@ class Changelist(object):
change_id = self._GetChangeDetail()['change_id']
change_desc.ensure_change_id(change_id)
else: # if not self.GetIssue()
if not options.force:
if not options.force and not options.message_file:
change_desc.prompt()
change_ids = git_footers.get_footer_change_id(change_desc.description)
if len(change_ids) == 1:
......@@ -4186,7 +4186,6 @@ def CMDupload(parser, args):
if options.message:
parser.error('Only one of --message and --message-file allowed.')
options.message = gclient_utils.FileRead(options.message_file)
options.message_file = None
if ([options.cq_dry_run,
options.use_commit_queue,
......
......@@ -294,6 +294,39 @@ class TestGitClBasic(unittest.TestCase):
self.assertEqual(options.force, True)
self.assertEqual(options.edit_description, False)
def test_upload_with_message_file_no_editor(self):
m = mock.patch('git_cl.ChangeDescription.prompt',
return_value=None).start()
mock.patch('git_cl.Changelist.GetRemoteBranch',
return_value=('foo', git_cl.DEFAULT_NEW_BRANCH)).start()
mock.patch('git_cl.GetTargetRef',
return_value='refs/heads/main').start()
mock.patch('git_cl.Changelist._GerritCommitMsgHookCheck',
lambda _, offer_removal: None).start()
mock.patch('git_cl.Changelist.GetIssue', return_value=None).start()
mock.patch('git_cl.Changelist.GetBranch',
side_effect=SystemExitMock).start()
mock.patch('git_cl.GenerateGerritChangeId', return_value=None).start()
mock.patch('git_cl.RunGit').start()
cl = git_cl.Changelist()
options = optparse.Values()
options.target_branch = 'refs/heads/master'
options.squash = True
options.edit_description = False
options.force = False
options.preserve_tryjobs = False
options.message_file = "message.txt"
with self.assertRaises(SystemExitMock):
cl.CMDUploadChange(options, [], 'foo', git_cl.ChangeDescription('bar'))
self.assertEqual(len(m.mock_calls), 0)
options.message_file = None
with self.assertRaises(SystemExitMock):
cl.CMDUploadChange(options, [], 'foo', git_cl.ChangeDescription('bar'))
self.assertEqual(len(m.mock_calls), 1)
def test_upload_to_old_default_retry_on_rollback(self):
"""Test when default branch migration had to be rolled back to old name"""
m = mock.patch('git_cl.Changelist._CMDUploadChange',
......
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