mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
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 <jochen@chromium.org> Commit-Queue: Michael Cui <mlcui@google.com>
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user