From 3da91715d3b7447cc012b3e38901b9e9a54039eb Mon Sep 17 00:00:00 2001 From: mlcui Date: Wed, 5 May 2021 10:00:30 +0000 Subject: [PATCH] git cl upload: Use default patchset message when user's message is "y" Users sometimes type in "y" to confirm the default patchset message, resulting in a patchset being uploaded with "y" as the message. We can make a fair assumption that no-one would willingly use a patchset message of "y", so this CL uses the default patchset message whenever this happens. (I have personally done this myself and have seen at least one other person do the same.) Bug: None Change-Id: Iad314d35aa830b62152ab2910eb37d876b7e450b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2861643 Reviewed-by: Jochen Eisinger Commit-Queue: Michael Cui --- git_cl.py | 4 ++++ tests/git_cl_test.py | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/git_cl.py b/git_cl.py index fc77ef8c2..5ad494790 100755 --- a/git_cl.py +++ b/git_cl.py @@ -1456,6 +1456,10 @@ class Changelist(object): if options.force or options.skip_title: return title user_title = gclient_utils.AskForData('Title for patchset [%s]: ' % title) + + # Use the default title if the user confirms the default with a 'y'. + if user_title.lower() == 'y': + return title return user_title or title def CMDUpload(self, options, git_diff_args, orig_args): diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index e93fecc5a..9ab5bb319 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -2997,6 +2997,12 @@ class TestGitCl(unittest.TestCase): class ChangelistTest(unittest.TestCase): + LAST_COMMIT_SUBJECT = 'Fixes goat teleporter destination to be Australia' + + def _mock_run_git(commands): + if commands == ['show', '-s', '--format=%s', 'HEAD']: + return ChangelistTest.LAST_COMMIT_SUBJECT + def setUp(self): super(ChangelistTest, self).setUp() mock.patch('gclient_utils.FileRead').start() @@ -3223,6 +3229,25 @@ class ChangelistTest(unittest.TestCase): gclient_utils.FileWrite.assert_called_once_with( '/tmp/fake-temp1', 'description') + @mock.patch('git_cl.RunGit', _mock_run_git) + def testDefaultTitleEmptyMessage(self): + cl = git_cl.Changelist() + cl.issue = 100 + options = optparse.Values({ + 'squash': True, + 'title': None, + 'message': None, + 'force': None, + 'skip_title': None + }) + + mock.patch('gclient_utils.AskForData', lambda _: user_title).start() + for user_title in ['', 'y', 'Y']: + self.assertEqual(cl._GetTitleForUpload(options), self.LAST_COMMIT_SUBJECT) + + for user_title in ['not empty', 'yes', 'YES']: + self.assertEqual(cl._GetTitleForUpload(options), user_title) + class CMDTestCaseBase(unittest.TestCase): _STATUSES = [