3 test_description
='test cherry-pick and revert with conflicts
6 + picked: rewrites foo to c
7 + base: rewrites foo to b
8 + initial: writes foo as a, unrelated as unrelated
15 git checkout
-f "$1^0" &&
16 git read-tree
-u --reset HEAD
&&
17 git clean
-d -f -f -q -x
20 test_expect_success setup
'
22 echo unrelated >unrelated &&
24 test_commit initial foo a &&
25 test_commit base foo b &&
26 test_commit picked foo c &&
27 test_commit --signoff picked-signed foo d &&
28 git checkout -b topic initial &&
29 test_commit redundant-pick foo c redundant &&
30 git commit --allow-empty --allow-empty-message &&
32 git checkout master &&
33 git config advice.detachedhead false
37 test_expect_success
'failed cherry-pick does not advance HEAD' '
38 pristine_detach initial &&
40 head=$(git rev-parse HEAD) &&
41 test_must_fail git cherry-pick picked &&
42 newhead=$(git rev-parse HEAD) &&
44 test "$head" = "$newhead"
47 test_expect_success
'advice from failed cherry-pick' "
48 pristine_detach initial &&
50 picked=\$(git rev-parse --short picked) &&
51 cat <<-EOF >expected &&
52 error: could not apply \$picked... picked
53 hint: after resolving the conflicts, mark the corrected paths
54 hint: with 'git add <paths>' or 'git rm <paths>'
55 hint: and commit the result with 'git commit'
57 test_must_fail git cherry-pick picked 2>actual &&
59 test_i18ncmp expected actual
62 test_expect_success
'advice from failed cherry-pick --no-commit' "
63 pristine_detach initial &&
65 picked=\$(git rev-parse --short picked) &&
66 cat <<-EOF >expected &&
67 error: could not apply \$picked... picked
68 hint: after resolving the conflicts, mark the corrected paths
69 hint: with 'git add <paths>' or 'git rm <paths>'
71 test_must_fail git cherry-pick --no-commit picked 2>actual &&
73 test_i18ncmp expected actual
76 test_expect_success
'failed cherry-pick sets CHERRY_PICK_HEAD' '
77 pristine_detach initial &&
78 test_must_fail git cherry-pick picked &&
79 test_cmp_rev picked CHERRY_PICK_HEAD
82 test_expect_success
'successful cherry-pick does not set CHERRY_PICK_HEAD' '
83 pristine_detach initial &&
84 git cherry-pick base &&
85 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
88 test_expect_success
'cherry-pick --no-commit does not set CHERRY_PICK_HEAD' '
89 pristine_detach initial &&
90 git cherry-pick --no-commit base &&
91 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
94 test_expect_success
'cherry-pick w/dirty tree does not set CHERRY_PICK_HEAD' '
95 pristine_detach initial &&
97 test_must_fail git cherry-pick base &&
98 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
101 test_expect_success \
102 'cherry-pick --strategy=resolve w/dirty tree does not set CHERRY_PICK_HEAD' '
103 pristine_detach initial &&
105 test_must_fail git cherry-pick --strategy=resolve base &&
106 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
109 test_expect_success
'GIT_CHERRY_PICK_HELP suppresses CHERRY_PICK_HEAD' '
110 pristine_detach initial &&
112 GIT_CHERRY_PICK_HELP="and then do something else" &&
113 export GIT_CHERRY_PICK_HELP &&
114 test_must_fail git cherry-pick picked
116 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
119 test_expect_success
'git reset clears CHERRY_PICK_HEAD' '
120 pristine_detach initial &&
122 test_must_fail git cherry-pick picked &&
125 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
128 test_expect_success
'failed commit does not clear CHERRY_PICK_HEAD' '
129 pristine_detach initial &&
131 test_must_fail git cherry-pick picked &&
132 test_must_fail git commit &&
134 test_cmp_rev picked CHERRY_PICK_HEAD
137 test_expect_success
'cancelled commit does not clear CHERRY_PICK_HEAD' '
138 pristine_detach initial &&
140 test_must_fail git cherry-pick picked &&
141 echo resolved >foo &&
143 git update-index --refresh -q &&
144 test_must_fail git diff-index --exit-code HEAD &&
148 test_must_fail git commit
151 test_cmp_rev picked CHERRY_PICK_HEAD
154 test_expect_success
'successful commit clears CHERRY_PICK_HEAD' '
155 pristine_detach initial &&
157 test_must_fail git cherry-pick picked &&
158 echo resolved >foo &&
162 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
164 test_expect_success
'successful final commit clears cherry-pick state' '
165 pristine_detach initial &&
167 test_must_fail git cherry-pick base picked-signed &&
168 echo resolved >foo &&
169 test_path_is_file .git/sequencer/todo &&
171 test_path_is_missing .git/sequencer
174 test_expect_success
'reset after final pick clears cherry-pick state' '
175 pristine_detach initial &&
177 test_must_fail git cherry-pick base picked-signed &&
178 echo resolved >foo &&
179 test_path_is_file .git/sequencer/todo &&
181 test_path_is_missing .git/sequencer
184 test_expect_success
'failed cherry-pick produces dirty index' '
185 pristine_detach initial &&
187 test_must_fail git cherry-pick picked &&
189 test_must_fail git update-index --refresh -q &&
190 test_must_fail git diff-index --exit-code HEAD
193 test_expect_success
'failed cherry-pick registers participants in index' '
194 pristine_detach initial &&
196 git checkout base -- foo &&
197 git ls-files --stage foo &&
198 git checkout initial -- foo &&
199 git ls-files --stage foo &&
200 git checkout picked -- foo &&
201 git ls-files --stage foo
207 " stages >expected &&
208 git read-tree -u --reset HEAD &&
210 test_must_fail git cherry-pick picked &&
211 git ls-files --stage --unmerged >actual &&
213 test_cmp expected actual
216 test_expect_success \
217 'cherry-pick conflict, ensure commit.cleanup = scissors places scissors line properly' '
218 pristine_detach initial &&
219 git config commit.cleanup scissors &&
220 cat <<-EOF >expected &&
223 # ------------------------ >8 ------------------------
224 # Do not modify or remove the line above.
225 # Everything below it will be ignored.
231 test_must_fail git cherry-pick picked &&
233 test_i18ncmp expected .git/MERGE_MSG
236 test_expect_success \
237 'cherry-pick conflict, ensure cleanup=scissors places scissors line properly' '
238 pristine_detach initial &&
239 git config --unset commit.cleanup &&
240 cat <<-EOF >expected &&
243 # ------------------------ >8 ------------------------
244 # Do not modify or remove the line above.
245 # Everything below it will be ignored.
251 test_must_fail git cherry-pick --cleanup=scissors picked &&
253 test_i18ncmp expected .git/MERGE_MSG
256 test_expect_success
'failed cherry-pick describes conflict in work tree' '
257 pristine_detach initial &&
258 cat <<-EOF >expected &&
266 test_must_fail git cherry-pick picked &&
268 sed "s/[a-f0-9]*\.\.\./objid/" foo >actual &&
269 test_cmp expected actual
272 test_expect_success
'diff3 -m style' '
273 pristine_detach initial &&
274 git config merge.conflictstyle diff3 &&
275 cat <<-EOF >expected &&
278 ||||||| parent of objid picked
285 test_must_fail git cherry-pick picked &&
287 sed "s/[a-f0-9]*\.\.\./objid/" foo >actual &&
288 test_cmp expected actual
291 test_expect_success
'revert also handles conflicts sanely' '
292 git config --unset merge.conflictstyle &&
293 pristine_detach initial &&
294 cat <<-EOF >expected &&
299 >>>>>>> parent of objid picked
302 git checkout picked -- foo &&
303 git ls-files --stage foo &&
304 git checkout initial -- foo &&
305 git ls-files --stage foo &&
306 git checkout base -- foo &&
307 git ls-files --stage foo
313 " stages >expected-stages &&
314 git read-tree -u --reset HEAD &&
316 head=$(git rev-parse HEAD) &&
317 test_must_fail git revert picked &&
318 newhead=$(git rev-parse HEAD) &&
319 git ls-files --stage --unmerged >actual-stages &&
321 test "$head" = "$newhead" &&
322 test_must_fail git update-index --refresh -q &&
323 test_must_fail git diff-index --exit-code HEAD &&
324 test_cmp expected-stages actual-stages &&
325 sed "s/[a-f0-9]*\.\.\./objid/" foo >actual &&
326 test_cmp expected actual
329 test_expect_success
'failed revert sets REVERT_HEAD' '
330 pristine_detach initial &&
331 test_must_fail git revert picked &&
332 test_cmp_rev picked REVERT_HEAD
335 test_expect_success
'successful revert does not set REVERT_HEAD' '
336 pristine_detach base &&
338 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
339 test_must_fail git rev-parse --verify REVERT_HEAD
342 test_expect_success
'revert --no-commit sets REVERT_HEAD' '
343 pristine_detach base &&
344 git revert --no-commit base &&
345 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
346 test_cmp_rev base REVERT_HEAD
349 test_expect_success
'revert w/dirty tree does not set REVERT_HEAD' '
350 pristine_detach base &&
352 test_must_fail git revert base &&
353 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
354 test_must_fail git rev-parse --verify REVERT_HEAD
357 test_expect_success
'GIT_CHERRY_PICK_HELP does not suppress REVERT_HEAD' '
358 pristine_detach initial &&
360 GIT_CHERRY_PICK_HELP="and then do something else" &&
361 GIT_REVERT_HELP="and then do something else, again" &&
362 export GIT_CHERRY_PICK_HELP GIT_REVERT_HELP &&
363 test_must_fail git revert picked
365 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
366 test_cmp_rev picked REVERT_HEAD
369 test_expect_success
'git reset clears REVERT_HEAD' '
370 pristine_detach initial &&
371 test_must_fail git revert picked &&
373 test_must_fail git rev-parse --verify REVERT_HEAD
376 test_expect_success
'failed commit does not clear REVERT_HEAD' '
377 pristine_detach initial &&
378 test_must_fail git revert picked &&
379 test_must_fail git commit &&
380 test_cmp_rev picked REVERT_HEAD
383 test_expect_success
'successful final commit clears revert state' '
384 pristine_detach picked-signed &&
386 test_must_fail git revert picked-signed base &&
387 echo resolved >foo &&
388 test_path_is_file .git/sequencer/todo &&
390 test_path_is_missing .git/sequencer
393 test_expect_success
'reset after final pick clears revert state' '
394 pristine_detach picked-signed &&
396 test_must_fail git revert picked-signed base &&
397 echo resolved >foo &&
398 test_path_is_file .git/sequencer/todo &&
400 test_path_is_missing .git/sequencer
403 test_expect_success
'revert conflict, diff3 -m style' '
404 pristine_detach initial &&
405 git config merge.conflictstyle diff3 &&
406 cat <<-EOF >expected &&
413 >>>>>>> parent of objid picked
416 test_must_fail git revert picked &&
418 sed "s/[a-f0-9]*\.\.\./objid/" foo >actual &&
419 test_cmp expected actual
422 test_expect_success \
423 'revert conflict, ensure commit.cleanup = scissors places scissors line properly' '
424 pristine_detach initial &&
425 git config commit.cleanup scissors &&
426 cat >expected <<-EOF &&
429 This reverts commit OBJID.
431 # ------------------------ >8 ------------------------
432 # Do not modify or remove the line above.
433 # Everything below it will be ignored.
439 test_must_fail git revert picked &&
441 sed "s/$OID_REGEX/OBJID/" .git/MERGE_MSG >actual &&
442 test_i18ncmp expected actual
445 test_expect_success \
446 'revert conflict, ensure cleanup=scissors places scissors line properly' '
447 pristine_detach initial &&
448 git config --unset commit.cleanup &&
449 cat >expected <<-EOF &&
452 This reverts commit OBJID.
454 # ------------------------ >8 ------------------------
455 # Do not modify or remove the line above.
456 # Everything below it will be ignored.
462 test_must_fail git revert --cleanup=scissors picked &&
464 sed "s/$OID_REGEX/OBJID/" .git/MERGE_MSG >actual &&
465 test_i18ncmp expected actual
468 test_expect_success
'failed cherry-pick does not forget -s' '
469 pristine_detach initial &&
470 test_must_fail git cherry-pick -s picked &&
471 test_i18ngrep -e "Signed-off-by" .git/MERGE_MSG
474 test_expect_success
'commit after failed cherry-pick does not add duplicated -s' '
475 pristine_detach initial &&
476 test_must_fail git cherry-pick -s picked-signed &&
478 test $(git show -s >tmp && grep -c "Signed-off-by" tmp && rm tmp) = 1
481 test_expect_success
'commit after failed cherry-pick adds -s at the right place' '
482 pristine_detach initial &&
483 test_must_fail git cherry-pick picked &&
487 # Do S-o-b and Conflicts appear in the right order?
488 cat <<-\EOF >expect &&
489 Signed-off-by: C O Mitter <committer@example.com>
492 grep -e "^# Conflicts:" -e '^Signed-off-by
' .git/COMMIT_EDITMSG >actual &&
493 test_cmp expect actual &&
495 cat <<-\EOF >expected &&
498 Signed-off-by: C O Mitter <committer@example.com>
501 git show -s --pretty=format:%B >actual &&
502 test_cmp expected actual
505 test_expect_success
'commit --amend -s places the sign-off at the right place' '
506 pristine_detach initial &&
507 test_must_fail git cherry-pick picked &&
509 # emulate old-style conflicts block
510 mv .git/MERGE_MSG .git/MERGE_MSG+ &&
511 sed -e "/^# Conflicts:/,\$s/^# *//" .git/MERGE_MSG+ >.git/MERGE_MSG &&
514 git commit --amend -s &&
516 # Do S-o-b and Conflicts appear in the right order?
517 cat <<-\EOF >expect &&
518 Signed-off-by: C O Mitter <committer@example.com>
521 grep -e "^Conflicts:" -e '^Signed-off-by
' .git/COMMIT_EDITMSG >actual &&
522 test_cmp expect actual
525 test_expect_success
'cherry-pick preserves sparse-checkout' '
526 pristine_detach initial &&
527 test_config core.sparseCheckout true &&
529 echo \"/*\" >.git/info/sparse-checkout
530 git read-tree --reset -u HEAD
531 rm .git/info/sparse-checkout" &&
532 echo /unrelated >.git/info/sparse-checkout &&
533 git read-tree --reset -u HEAD &&
534 test_must_fail git cherry-pick -Xours picked>actual &&
535 test_i18ngrep ! "Changes not staged for commit:" actual
538 test_expect_success
'cherry-pick --continue remembers --keep-redundant-commits' '
539 test_when_finished "git cherry-pick --abort || :" &&
540 pristine_detach initial &&
541 test_must_fail git cherry-pick --keep-redundant-commits picked redundant &&
544 git cherry-pick --continue
547 test_expect_success
'cherry-pick --continue remembers --allow-empty and --allow-empty-message' '
548 test_when_finished "git cherry-pick --abort || :" &&
549 pristine_detach initial &&
550 test_must_fail git cherry-pick --allow-empty --allow-empty-message \
554 git cherry-pick --continue