utf8: fix overflow when returning string width
[alt-git.git] / t / t3507-cherry-pick-conflict.sh
bloba21adcf0e43a6d6003e60809a3dc8f20772fef2e
1 #!/bin/sh
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
12 . ./test-lib.sh
14 pristine_detach () {
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 &&
23 git add 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 &&
31 git tag empty &&
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'
56 EOF
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>'
70 EOF
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 &&
96 echo foo >foo &&
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 &&
104 echo foo >foo &&
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
115 ) &&
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 &&
123 git reset &&
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 &&
142 git add foo &&
143 git update-index --refresh -q &&
144 test_must_fail git diff-index --exit-code HEAD &&
146 GIT_EDITOR=false &&
147 export GIT_EDITOR &&
148 test_must_fail git commit
149 ) &&
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 &&
159 git add foo &&
160 git commit &&
162 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
165 test_expect_success 'partial commit of cherry-pick fails' '
166 pristine_detach initial &&
168 test_must_fail git cherry-pick picked &&
169 echo resolved >foo &&
170 git add foo &&
171 test_must_fail git commit foo 2>err &&
173 test_i18ngrep "cannot do a partial commit during a cherry-pick." err
176 test_expect_success 'commit --amend of cherry-pick fails' '
177 pristine_detach initial &&
179 test_must_fail git cherry-pick picked &&
180 echo resolved >foo &&
181 git add foo &&
182 test_must_fail git commit --amend 2>err &&
184 test_i18ngrep "in the middle of a cherry-pick -- cannot amend." err
187 test_expect_success 'successful final commit clears cherry-pick state' '
188 pristine_detach initial &&
190 test_must_fail git cherry-pick base picked-signed &&
191 echo resolved >foo &&
192 test_path_is_file .git/sequencer/todo &&
193 git commit -a &&
194 test_path_is_missing .git/sequencer
197 test_expect_success 'reset after final pick clears cherry-pick state' '
198 pristine_detach initial &&
200 test_must_fail git cherry-pick base picked-signed &&
201 echo resolved >foo &&
202 test_path_is_file .git/sequencer/todo &&
203 git reset &&
204 test_path_is_missing .git/sequencer
207 test_expect_success 'failed cherry-pick produces dirty index' '
208 pristine_detach initial &&
210 test_must_fail git cherry-pick picked &&
212 test_must_fail git update-index --refresh -q &&
213 test_must_fail git diff-index --exit-code HEAD
216 test_expect_success 'failed cherry-pick registers participants in index' '
217 pristine_detach initial &&
219 git checkout base -- foo &&
220 git ls-files --stage foo &&
221 git checkout initial -- foo &&
222 git ls-files --stage foo &&
223 git checkout picked -- foo &&
224 git ls-files --stage foo
225 } >stages &&
226 sed "
227 1 s/ 0 / 1 /
228 2 s/ 0 / 2 /
229 3 s/ 0 / 3 /
230 " stages >expected &&
231 git read-tree -u --reset HEAD &&
233 test_must_fail git cherry-pick picked &&
234 git ls-files --stage --unmerged >actual &&
236 test_cmp expected actual
239 test_expect_success \
240 'cherry-pick conflict, ensure commit.cleanup = scissors places scissors line properly' '
241 pristine_detach initial &&
242 git config commit.cleanup scissors &&
243 cat <<-EOF >expected &&
244 picked
246 # ------------------------ >8 ------------------------
247 # Do not modify or remove the line above.
248 # Everything below it will be ignored.
250 # Conflicts:
251 # foo
254 test_must_fail git cherry-pick picked &&
256 test_i18ncmp expected .git/MERGE_MSG
259 test_expect_success \
260 'cherry-pick conflict, ensure cleanup=scissors places scissors line properly' '
261 pristine_detach initial &&
262 git config --unset commit.cleanup &&
263 cat <<-EOF >expected &&
264 picked
266 # ------------------------ >8 ------------------------
267 # Do not modify or remove the line above.
268 # Everything below it will be ignored.
270 # Conflicts:
271 # foo
274 test_must_fail git cherry-pick --cleanup=scissors picked &&
276 test_i18ncmp expected .git/MERGE_MSG
279 test_expect_success 'failed cherry-pick describes conflict in work tree' '
280 pristine_detach initial &&
281 cat <<-EOF >expected &&
282 <<<<<<< HEAD
284 =======
286 >>>>>>> objid (picked)
289 test_must_fail git cherry-pick picked &&
291 sed "s/[a-f0-9]* (/objid (/" foo >actual &&
292 test_cmp expected actual
295 test_expect_success 'diff3 -m style' '
296 pristine_detach initial &&
297 git config merge.conflictstyle diff3 &&
298 cat <<-EOF >expected &&
299 <<<<<<< HEAD
301 ||||||| parent of objid (picked)
303 =======
305 >>>>>>> objid (picked)
308 test_must_fail git cherry-pick picked &&
310 sed "s/[a-f0-9]* (/objid (/" foo >actual &&
311 test_cmp expected actual
314 test_expect_success 'revert also handles conflicts sanely' '
315 git config --unset merge.conflictstyle &&
316 pristine_detach initial &&
317 cat <<-EOF >expected &&
318 <<<<<<< HEAD
320 =======
322 >>>>>>> parent of objid (picked)
325 git checkout picked -- foo &&
326 git ls-files --stage foo &&
327 git checkout initial -- foo &&
328 git ls-files --stage foo &&
329 git checkout base -- foo &&
330 git ls-files --stage foo
331 } >stages &&
332 sed "
333 1 s/ 0 / 1 /
334 2 s/ 0 / 2 /
335 3 s/ 0 / 3 /
336 " stages >expected-stages &&
337 git read-tree -u --reset HEAD &&
339 head=$(git rev-parse HEAD) &&
340 test_must_fail git revert picked &&
341 newhead=$(git rev-parse HEAD) &&
342 git ls-files --stage --unmerged >actual-stages &&
344 test "$head" = "$newhead" &&
345 test_must_fail git update-index --refresh -q &&
346 test_must_fail git diff-index --exit-code HEAD &&
347 test_cmp expected-stages actual-stages &&
348 sed "s/[a-f0-9]* (/objid (/" foo >actual &&
349 test_cmp expected actual
352 test_expect_success 'failed revert sets REVERT_HEAD' '
353 pristine_detach initial &&
354 test_must_fail git revert picked &&
355 test_cmp_rev picked REVERT_HEAD
358 test_expect_success 'successful revert does not set REVERT_HEAD' '
359 pristine_detach base &&
360 git revert base &&
361 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
362 test_must_fail git rev-parse --verify REVERT_HEAD
365 test_expect_success 'revert --no-commit sets REVERT_HEAD' '
366 pristine_detach base &&
367 git revert --no-commit base &&
368 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
369 test_cmp_rev base REVERT_HEAD
372 test_expect_success 'revert w/dirty tree does not set REVERT_HEAD' '
373 pristine_detach base &&
374 echo foo >foo &&
375 test_must_fail git revert base &&
376 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
377 test_must_fail git rev-parse --verify REVERT_HEAD
380 test_expect_success 'GIT_CHERRY_PICK_HELP does not suppress REVERT_HEAD' '
381 pristine_detach initial &&
383 GIT_CHERRY_PICK_HELP="and then do something else" &&
384 GIT_REVERT_HELP="and then do something else, again" &&
385 export GIT_CHERRY_PICK_HELP GIT_REVERT_HELP &&
386 test_must_fail git revert picked
387 ) &&
388 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
389 test_cmp_rev picked REVERT_HEAD
392 test_expect_success 'git reset clears REVERT_HEAD' '
393 pristine_detach initial &&
394 test_must_fail git revert picked &&
395 git reset &&
396 test_must_fail git rev-parse --verify REVERT_HEAD
399 test_expect_success 'failed commit does not clear REVERT_HEAD' '
400 pristine_detach initial &&
401 test_must_fail git revert picked &&
402 test_must_fail git commit &&
403 test_cmp_rev picked REVERT_HEAD
406 test_expect_success 'successful final commit clears revert state' '
407 pristine_detach picked-signed &&
409 test_must_fail git revert picked-signed base &&
410 echo resolved >foo &&
411 test_path_is_file .git/sequencer/todo &&
412 git commit -a &&
413 test_path_is_missing .git/sequencer
416 test_expect_success 'reset after final pick clears revert state' '
417 pristine_detach picked-signed &&
419 test_must_fail git revert picked-signed base &&
420 echo resolved >foo &&
421 test_path_is_file .git/sequencer/todo &&
422 git reset &&
423 test_path_is_missing .git/sequencer
426 test_expect_success 'revert conflict, diff3 -m style' '
427 pristine_detach initial &&
428 git config merge.conflictstyle diff3 &&
429 cat <<-EOF >expected &&
430 <<<<<<< HEAD
432 ||||||| objid (picked)
434 =======
436 >>>>>>> parent of objid (picked)
439 test_must_fail git revert picked &&
441 sed "s/[a-f0-9]* (/objid (/" foo >actual &&
442 test_cmp expected actual
445 test_expect_success \
446 'revert conflict, ensure commit.cleanup = scissors places scissors line properly' '
447 pristine_detach initial &&
448 git config commit.cleanup scissors &&
449 cat >expected <<-EOF &&
450 Revert "picked"
452 This reverts commit OBJID.
454 # ------------------------ >8 ------------------------
455 # Do not modify or remove the line above.
456 # Everything below it will be ignored.
458 # Conflicts:
459 # foo
462 test_must_fail git revert picked &&
464 sed "s/$OID_REGEX/OBJID/" .git/MERGE_MSG >actual &&
465 test_i18ncmp expected actual
468 test_expect_success \
469 'revert conflict, ensure cleanup=scissors places scissors line properly' '
470 pristine_detach initial &&
471 git config --unset commit.cleanup &&
472 cat >expected <<-EOF &&
473 Revert "picked"
475 This reverts commit OBJID.
477 # ------------------------ >8 ------------------------
478 # Do not modify or remove the line above.
479 # Everything below it will be ignored.
481 # Conflicts:
482 # foo
485 test_must_fail git revert --cleanup=scissors picked &&
487 sed "s/$OID_REGEX/OBJID/" .git/MERGE_MSG >actual &&
488 test_i18ncmp expected actual
491 test_expect_success 'failed cherry-pick does not forget -s' '
492 pristine_detach initial &&
493 test_must_fail git cherry-pick -s picked &&
494 test_i18ngrep -e "Signed-off-by" .git/MERGE_MSG
497 test_expect_success 'commit after failed cherry-pick does not add duplicated -s' '
498 pristine_detach initial &&
499 test_must_fail git cherry-pick -s picked-signed &&
500 git commit -a -s &&
501 test $(git show -s >tmp && grep -c "Signed-off-by" tmp && rm tmp) = 1
504 test_expect_success 'commit after failed cherry-pick adds -s at the right place' '
505 pristine_detach initial &&
506 test_must_fail git cherry-pick picked &&
508 git commit -a -s &&
510 # Do S-o-b and Conflicts appear in the right order?
511 cat <<-\EOF >expect &&
512 Signed-off-by: C O Mitter <committer@example.com>
513 # Conflicts:
515 grep -e "^# Conflicts:" -e "^Signed-off-by" .git/COMMIT_EDITMSG >actual &&
516 test_cmp expect actual &&
518 cat <<-\EOF >expected &&
519 picked
521 Signed-off-by: C O Mitter <committer@example.com>
524 git show -s --pretty=format:%B >actual &&
525 test_cmp expected actual
528 test_expect_success 'commit --amend -s places the sign-off at the right place' '
529 pristine_detach initial &&
530 test_must_fail git cherry-pick picked &&
532 # emulate old-style conflicts block
533 mv .git/MERGE_MSG .git/MERGE_MSG+ &&
534 sed -e "/^# Conflicts:/,\$s/^# *//" .git/MERGE_MSG+ >.git/MERGE_MSG &&
536 git commit -a &&
537 git commit --amend -s &&
539 # Do S-o-b and Conflicts appear in the right order?
540 cat <<-\EOF >expect &&
541 Signed-off-by: C O Mitter <committer@example.com>
542 Conflicts:
544 grep -e "^Conflicts:" -e "^Signed-off-by" .git/COMMIT_EDITMSG >actual &&
545 test_cmp expect actual
548 test_expect_success 'cherry-pick preserves sparse-checkout' '
549 pristine_detach initial &&
550 test_config core.sparseCheckout true &&
551 test_when_finished "
552 echo \"/*\" >.git/info/sparse-checkout
553 git read-tree --reset -u HEAD
554 rm .git/info/sparse-checkout" &&
555 echo /unrelated >.git/info/sparse-checkout &&
556 git read-tree --reset -u HEAD &&
557 test_must_fail git cherry-pick -Xours picked>actual &&
558 test_i18ngrep ! "Changes not staged for commit:" actual
561 test_expect_success 'cherry-pick --continue remembers --keep-redundant-commits' '
562 test_when_finished "git cherry-pick --abort || :" &&
563 pristine_detach initial &&
564 test_must_fail git cherry-pick --keep-redundant-commits picked redundant &&
565 echo c >foo &&
566 git add foo &&
567 git cherry-pick --continue
570 test_expect_success 'cherry-pick --continue remembers --allow-empty and --allow-empty-message' '
571 test_when_finished "git cherry-pick --abort || :" &&
572 pristine_detach initial &&
573 test_must_fail git cherry-pick --allow-empty --allow-empty-message \
574 picked empty &&
575 echo c >foo &&
576 git add foo &&
577 git cherry-pick --continue
580 test_done