|
|
|
@ -1514,6 +1514,159 @@ class TestGitCl(unittest.TestCase):
|
|
|
|
|
external_parent='newparent',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@mock.patch('git_cl.Changelist.GetGerritHost',
|
|
|
|
|
return_value='chromium-review.googlesource.com')
|
|
|
|
|
@mock.patch('git_cl.Changelist.GetRemoteBranch',
|
|
|
|
|
return_value=('origin', 'refs/remotes/origin/main'))
|
|
|
|
|
@mock.patch('git_cl.Changelist.PostUploadUpdates')
|
|
|
|
|
@mock.patch('git_cl.Changelist._RunGitPushWithTraces')
|
|
|
|
|
@mock.patch('git_cl._UploadAllPrecheck')
|
|
|
|
|
@mock.patch('git_cl.Changelist.PrepareCherryPickSquashedCommit')
|
|
|
|
|
def test_upload_all_squashed_cherry_pick(self, mockCherryPickCommit,
|
|
|
|
|
mockUploadAllPrecheck,
|
|
|
|
|
mockRunGitPush,
|
|
|
|
|
mockPostUploadUpdates, *_mocks):
|
|
|
|
|
# Set up
|
|
|
|
|
cls = [
|
|
|
|
|
git_cl.Changelist(branchref='refs/heads/current-branch', issue='12345'),
|
|
|
|
|
git_cl.Changelist(branchref='refs/heads/upstream-branch')
|
|
|
|
|
]
|
|
|
|
|
mockUploadAllPrecheck.return_value = (cls, True)
|
|
|
|
|
|
|
|
|
|
upstream_gerrit_commit = 'upstream-commit'
|
|
|
|
|
self.mockGit.config[
|
|
|
|
|
'branch.upstream-branch.gerritsquashhash'] = upstream_gerrit_commit
|
|
|
|
|
|
|
|
|
|
reviewers = []
|
|
|
|
|
ccs = []
|
|
|
|
|
commit_to_push = 'commit-to-push'
|
|
|
|
|
new_last_upload = 'new-last-upload'
|
|
|
|
|
change_desc = git_cl.ChangeDescription('stonks/nChange-Id:ec15e81197380')
|
|
|
|
|
new_upload = git_cl._NewUpload(reviewers, ccs, commit_to_push,
|
|
|
|
|
new_last_upload, upstream_gerrit_commit,
|
|
|
|
|
change_desc)
|
|
|
|
|
mockCherryPickCommit.return_value = new_upload
|
|
|
|
|
|
|
|
|
|
options = optparse.Values()
|
|
|
|
|
options.send_mail = options.private = False
|
|
|
|
|
options.squash = True
|
|
|
|
|
options.title = None
|
|
|
|
|
options.message = 'honk stonk'
|
|
|
|
|
options.topic = 'circus'
|
|
|
|
|
options.enable_auto_submit = False
|
|
|
|
|
options.set_bot_commit = False
|
|
|
|
|
options.cq_dry_run = False
|
|
|
|
|
options.use_commit_queue = options.cq_quick_run = False
|
|
|
|
|
options.hashtags = ['cow']
|
|
|
|
|
options.target_branch = None
|
|
|
|
|
orig_args = []
|
|
|
|
|
|
|
|
|
|
mockRunGitPush.return_value = (
|
|
|
|
|
'remote: https://chromium-review.'
|
|
|
|
|
'googlesource.com/c/chromium/circus/clown/+/1234 stonks')
|
|
|
|
|
|
|
|
|
|
# Call
|
|
|
|
|
git_cl.UploadAllSquashed(options, orig_args)
|
|
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
|
mockCherryPickCommit.assert_called_once_with(options,
|
|
|
|
|
upstream_gerrit_commit)
|
|
|
|
|
expected_refspec = ('commit-to-push:refs/for/refs/heads/main%notify=NONE,'
|
|
|
|
|
'm=honk_stonk,topic=circus,hashtag=cow')
|
|
|
|
|
expected_refspec_opts = [
|
|
|
|
|
'notify=NONE', 'm=honk_stonk', 'topic=circus', 'hashtag=cow'
|
|
|
|
|
]
|
|
|
|
|
mockRunGitPush.assert_called_once_with(expected_refspec,
|
|
|
|
|
expected_refspec_opts, mock.ANY)
|
|
|
|
|
mockPostUploadUpdates.assert_called_once_with(options, new_upload, '1234')
|
|
|
|
|
|
|
|
|
|
@mock.patch('git_cl.Changelist.GetGerritHost',
|
|
|
|
|
return_value='chromium-review.googlesource.com')
|
|
|
|
|
@mock.patch('git_cl.Changelist.GetRemoteBranch',
|
|
|
|
|
return_value=('origin', 'refs/remotes/origin/main'))
|
|
|
|
|
@mock.patch('git_cl.Changelist.GetCommonAncestorWithUpstream',
|
|
|
|
|
return_value='current-upstream-ancestor')
|
|
|
|
|
@mock.patch('git_cl.Changelist.PostUploadUpdates')
|
|
|
|
|
@mock.patch('git_cl.Changelist._RunGitPushWithTraces')
|
|
|
|
|
@mock.patch('git_cl._UploadAllPrecheck')
|
|
|
|
|
@mock.patch('git_cl.Changelist.PrepareSquashedCommit')
|
|
|
|
|
def test_upload_all_squashed(self, mockSquashedCommit, mockUploadAllPrecheck,
|
|
|
|
|
mockRunGitPush, mockPostUploadUpdates, *_mocks):
|
|
|
|
|
# Set up
|
|
|
|
|
cls = [
|
|
|
|
|
git_cl.Changelist(branchref='refs/heads/current-branch', issue='12345'),
|
|
|
|
|
git_cl.Changelist(branchref='refs/heads/upstream-branch')
|
|
|
|
|
]
|
|
|
|
|
mockUploadAllPrecheck.return_value = (cls, False)
|
|
|
|
|
|
|
|
|
|
reviewers = []
|
|
|
|
|
ccs = []
|
|
|
|
|
|
|
|
|
|
current_commit_to_push = 'commit-to-push'
|
|
|
|
|
current_new_last_upload = 'new-last-upload'
|
|
|
|
|
change_desc = git_cl.ChangeDescription('stonks/nChange-Id:ec15e81197380')
|
|
|
|
|
new_upload_current = git_cl._NewUpload(reviewers, ccs,
|
|
|
|
|
current_commit_to_push,
|
|
|
|
|
current_new_last_upload,
|
|
|
|
|
'current-upstream-ancestor',
|
|
|
|
|
change_desc)
|
|
|
|
|
|
|
|
|
|
upstream_desc = git_cl.ChangeDescription('kwak')
|
|
|
|
|
upstream_parent = 'origin-commit'
|
|
|
|
|
upstream_new_last_upload = 'upstrea-last-upload'
|
|
|
|
|
upstream_commit_to_push = 'upstream_push_commit'
|
|
|
|
|
new_upload_upstream = git_cl._NewUpload(reviewers, ccs,
|
|
|
|
|
upstream_commit_to_push,
|
|
|
|
|
upstream_new_last_upload,
|
|
|
|
|
upstream_parent, upstream_desc)
|
|
|
|
|
mockSquashedCommit.side_effect = [new_upload_upstream, new_upload_current]
|
|
|
|
|
|
|
|
|
|
options = optparse.Values()
|
|
|
|
|
options.send_mail = options.private = False
|
|
|
|
|
options.squash = True
|
|
|
|
|
options.title = None
|
|
|
|
|
options.message = 'honk stonk'
|
|
|
|
|
options.topic = 'circus'
|
|
|
|
|
options.enable_auto_submit = False
|
|
|
|
|
options.set_bot_commit = False
|
|
|
|
|
options.cq_dry_run = False
|
|
|
|
|
options.use_commit_queue = options.cq_quick_run = False
|
|
|
|
|
options.hashtags = ['cow']
|
|
|
|
|
options.target_branch = None
|
|
|
|
|
orig_args = []
|
|
|
|
|
|
|
|
|
|
mockRunGitPush.return_value = (
|
|
|
|
|
'remote: https://chromium-review.'
|
|
|
|
|
'googlesource.com/c/chromium/circus/clown/+/1233 kwak'
|
|
|
|
|
'\n'
|
|
|
|
|
'remote: https://chromium-review.'
|
|
|
|
|
'googlesource.com/c/chromium/circus/clown/+/1234 stonks')
|
|
|
|
|
|
|
|
|
|
# Call
|
|
|
|
|
git_cl.UploadAllSquashed(options, orig_args)
|
|
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
|
self.assertEqual(mockSquashedCommit.mock_calls, [
|
|
|
|
|
mock.call(options, parent=None, end_commit='current-upstream-ancestor'),
|
|
|
|
|
mock.call(options, parent=upstream_commit_to_push, end_commit=None)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expected_refspec = ('commit-to-push:refs/for/refs/heads/main%notify=NONE,'
|
|
|
|
|
'm=honk_stonk,topic=circus,hashtag=cow')
|
|
|
|
|
expected_refspec_opts = [
|
|
|
|
|
'notify=NONE', 'm=honk_stonk', 'topic=circus', 'hashtag=cow'
|
|
|
|
|
]
|
|
|
|
|
expected_refspec = ('commit-to-push:refs/for/refs/heads/main%notify=NONE,'
|
|
|
|
|
'topic=circus,hashtag=cow')
|
|
|
|
|
expected_refspec_opts = ['notify=NONE', 'topic=circus', 'hashtag=cow']
|
|
|
|
|
mockRunGitPush.assert_called_once_with(expected_refspec,
|
|
|
|
|
expected_refspec_opts, mock.ANY)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(mockPostUploadUpdates.mock_calls, [
|
|
|
|
|
mock.call(options, new_upload_upstream, '1233'),
|
|
|
|
|
mock.call(options, new_upload_current, '1234')
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
@mock.patch(
|
|
|
|
|
'git_cl.Changelist._GerritCommitMsgHookCheck', lambda offer_removal: None)
|
|
|
|
|
@mock.patch('git_cl.Changelist.FetchUpstreamTuple')
|
|
|
|
|