l10n: fr v2.28.0 round 1
[git/debian.git] / t / t3510-cherry-pick-sequence.sh
blob5b94fdaa6713a2bcf7958d6630925a09fea05ed6
1 #!/bin/sh
3 test_description='Test cherry-pick continuation features
5 + conflicting: rewrites unrelated to conflicting
6 + yetanotherpick: rewrites foo to e
7 + anotherpick: rewrites foo to d
8 + picked: rewrites foo to c
9 + unrelatedpick: rewrites unrelated to reallyunrelated
10 + base: rewrites foo to b
11 + initial: writes foo as a, unrelated as unrelated
15 . ./test-lib.sh
17 # Repeat first match 10 times
18 _r10='\1\1\1\1\1\1\1\1\1\1'
20 pristine_detach () {
21 git cherry-pick --quit &&
22 git checkout -f "$1^0" &&
23 git read-tree -u --reset HEAD &&
24 git clean -d -f -f -q -x
27 test_expect_success setup '
28 git config advice.detachedhead false &&
29 echo unrelated >unrelated &&
30 git add unrelated &&
31 test_commit initial foo a &&
32 test_commit base foo b &&
33 test_commit unrelatedpick unrelated reallyunrelated &&
34 test_commit picked foo c &&
35 test_commit anotherpick foo d &&
36 test_commit yetanotherpick foo e &&
37 pristine_detach initial &&
38 test_commit conflicting unrelated
41 test_expect_success 'cherry-pick persists data on failure' '
42 pristine_detach initial &&
43 test_expect_code 1 git cherry-pick -s base..anotherpick &&
44 test_path_is_dir .git/sequencer &&
45 test_path_is_file .git/sequencer/head &&
46 test_path_is_file .git/sequencer/todo &&
47 test_path_is_file .git/sequencer/opts
50 test_expect_success 'cherry-pick mid-cherry-pick-sequence' '
51 pristine_detach initial &&
52 test_must_fail git cherry-pick base..anotherpick &&
53 test_cmp_rev picked CHERRY_PICK_HEAD &&
54 # "oops, I forgot that these patches rely on the change from base"
55 git checkout HEAD foo &&
56 git cherry-pick base &&
57 git cherry-pick picked &&
58 git cherry-pick --continue &&
59 git diff --exit-code anotherpick
62 test_expect_success 'cherry-pick persists opts correctly' '
63 pristine_detach initial &&
64 # to make sure that the session to cherry-pick a sequence
65 # gets interrupted, use a high-enough number that is larger
66 # than the number of parents of any commit we have created
67 mainline=4 &&
68 test_expect_code 128 git cherry-pick -s -m $mainline --strategy=recursive -X patience -X ours initial..anotherpick &&
69 test_path_is_dir .git/sequencer &&
70 test_path_is_file .git/sequencer/head &&
71 test_path_is_file .git/sequencer/todo &&
72 test_path_is_file .git/sequencer/opts &&
73 echo "true" >expect &&
74 git config --file=.git/sequencer/opts --get-all options.signoff >actual &&
75 test_cmp expect actual &&
76 echo "$mainline" >expect &&
77 git config --file=.git/sequencer/opts --get-all options.mainline >actual &&
78 test_cmp expect actual &&
79 echo "recursive" >expect &&
80 git config --file=.git/sequencer/opts --get-all options.strategy >actual &&
81 test_cmp expect actual &&
82 cat >expect <<-\EOF &&
83 patience
84 ours
85 EOF
86 git config --file=.git/sequencer/opts --get-all options.strategy-option >actual &&
87 test_cmp expect actual
90 test_expect_success 'cherry-pick cleans up sequencer state upon success' '
91 pristine_detach initial &&
92 git cherry-pick initial..picked &&
93 test_path_is_missing .git/sequencer
96 test_expect_success 'cherry-pick --skip requires cherry-pick in progress' '
97 pristine_detach initial &&
98 test_must_fail git cherry-pick --skip
101 test_expect_success 'revert --skip requires revert in progress' '
102 pristine_detach initial &&
103 test_must_fail git revert --skip
106 test_expect_success 'cherry-pick --skip to skip commit' '
107 pristine_detach initial &&
108 test_must_fail git cherry-pick anotherpick &&
109 test_must_fail git revert --skip &&
110 git cherry-pick --skip &&
111 test_cmp_rev initial HEAD &&
112 test_path_is_missing .git/CHERRY_PICK_HEAD
115 test_expect_success 'revert --skip to skip commit' '
116 pristine_detach anotherpick &&
117 test_must_fail git revert anotherpick~1 &&
118 test_must_fail git cherry-pick --skip &&
119 git revert --skip &&
120 test_cmp_rev anotherpick HEAD
123 test_expect_success 'skip "empty" commit' '
124 pristine_detach picked &&
125 test_commit dummy foo d &&
126 test_must_fail git cherry-pick anotherpick 2>err &&
127 test_i18ngrep "git cherry-pick --skip" err &&
128 git cherry-pick --skip &&
129 test_cmp_rev dummy HEAD
132 test_expect_success 'skip a commit and check if rest of sequence is correct' '
133 pristine_detach initial &&
134 echo e >expect &&
135 cat >expect.log <<-EOF &&
136 OBJID
137 :100644 100644 OBJID OBJID M foo
138 OBJID
139 :100644 100644 OBJID OBJID M foo
140 OBJID
141 :100644 100644 OBJID OBJID M unrelated
142 OBJID
143 :000000 100644 OBJID OBJID A foo
144 :000000 100644 OBJID OBJID A unrelated
146 test_must_fail git cherry-pick base..yetanotherpick &&
147 test_must_fail git cherry-pick --skip &&
148 echo d >foo &&
149 git add foo &&
150 git cherry-pick --continue &&
152 git rev-list HEAD |
153 git diff-tree --root --stdin |
154 sed "s/$OID_REGEX/OBJID/g"
155 } >actual.log &&
156 test_cmp expect foo &&
157 test_cmp expect.log actual.log
160 test_expect_success 'check advice when we move HEAD by committing' '
161 pristine_detach initial &&
162 cat >expect <<-EOF &&
163 error: there is nothing to skip
164 hint: have you committed already?
165 hint: try "git cherry-pick --continue"
166 fatal: cherry-pick failed
168 test_must_fail git cherry-pick base..yetanotherpick &&
169 echo c >foo &&
170 git commit -a &&
171 test_path_is_missing .git/CHERRY_PICK_HEAD &&
172 test_must_fail git cherry-pick --skip 2>advice &&
173 test_i18ncmp expect advice
176 test_expect_success 'selectively advise --skip while launching another sequence' '
177 pristine_detach initial &&
178 cat >expect <<-EOF &&
179 error: cherry-pick is already in progress
180 hint: try "git cherry-pick (--continue | --skip | --abort | --quit)"
181 fatal: cherry-pick failed
183 test_must_fail git cherry-pick picked..yetanotherpick &&
184 test_must_fail git cherry-pick picked..yetanotherpick 2>advice &&
185 test_i18ncmp expect advice &&
186 cat >expect <<-EOF &&
187 error: cherry-pick is already in progress
188 hint: try "git cherry-pick (--continue | --abort | --quit)"
189 fatal: cherry-pick failed
191 git reset --merge &&
192 test_must_fail git cherry-pick picked..yetanotherpick 2>advice &&
193 test_i18ncmp expect advice
196 test_expect_success 'allow skipping commit but not abort for a new history' '
197 pristine_detach initial &&
198 cat >expect <<-EOF &&
199 error: cannot abort from a branch yet to be born
200 fatal: cherry-pick failed
202 git checkout --orphan new_disconnected &&
203 git reset --hard &&
204 test_must_fail git cherry-pick anotherpick &&
205 test_must_fail git cherry-pick --abort 2>advice &&
206 git cherry-pick --skip &&
207 test_i18ncmp expect advice
210 test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' '
211 pristine_detach initial &&
212 git rm --cached unrelated &&
213 git commit -m "untrack unrelated" &&
214 test_must_fail git cherry-pick initial base &&
215 test_path_is_missing .git/CHERRY_PICK_HEAD &&
216 git cherry-pick --skip
219 test_expect_success '--quit does not complain when no cherry-pick is in progress' '
220 pristine_detach initial &&
221 git cherry-pick --quit
224 test_expect_success '--abort requires cherry-pick in progress' '
225 pristine_detach initial &&
226 test_must_fail git cherry-pick --abort
229 test_expect_success '--quit cleans up sequencer state' '
230 pristine_detach initial &&
231 test_expect_code 1 git cherry-pick base..picked &&
232 git cherry-pick --quit &&
233 test_path_is_missing .git/sequencer &&
234 test_path_is_missing .git/CHERRY_PICK_HEAD
237 test_expect_success '--quit keeps HEAD and conflicted index intact' '
238 pristine_detach initial &&
239 cat >expect <<-\EOF &&
240 OBJID
241 :100644 100644 OBJID OBJID M unrelated
242 OBJID
243 :000000 100644 OBJID OBJID A foo
244 :000000 100644 OBJID OBJID A unrelated
246 test_expect_code 1 git cherry-pick base..picked &&
247 git cherry-pick --quit &&
248 test_path_is_missing .git/sequencer &&
249 test_must_fail git update-index --refresh &&
251 git rev-list HEAD |
252 git diff-tree --root --stdin |
253 sed "s/$OID_REGEX/OBJID/g"
254 } >actual &&
255 test_cmp expect actual
258 test_expect_success '--abort to cancel multiple cherry-pick' '
259 pristine_detach initial &&
260 test_expect_code 1 git cherry-pick base..anotherpick &&
261 git cherry-pick --abort &&
262 test_path_is_missing .git/sequencer &&
263 test_path_is_missing .git/CHERRY_PICK_HEAD &&
264 test_cmp_rev initial HEAD &&
265 git update-index --refresh &&
266 git diff-index --exit-code HEAD
269 test_expect_success '--abort to cancel single cherry-pick' '
270 pristine_detach initial &&
271 test_expect_code 1 git cherry-pick picked &&
272 git cherry-pick --abort &&
273 test_path_is_missing .git/sequencer &&
274 test_path_is_missing .git/CHERRY_PICK_HEAD &&
275 test_cmp_rev initial HEAD &&
276 git update-index --refresh &&
277 git diff-index --exit-code HEAD
280 test_expect_success '--abort does not unsafely change HEAD' '
281 pristine_detach initial &&
282 test_must_fail git cherry-pick picked anotherpick &&
283 git reset --hard base &&
284 test_must_fail git cherry-pick picked anotherpick &&
285 git cherry-pick --abort 2>actual &&
286 test_i18ngrep "You seem to have moved HEAD" actual &&
287 test_cmp_rev base HEAD
290 test_expect_success 'cherry-pick --abort to cancel multiple revert' '
291 pristine_detach anotherpick &&
292 test_expect_code 1 git revert base..picked &&
293 git cherry-pick --abort &&
294 test_path_is_missing .git/sequencer &&
295 test_path_is_missing .git/CHERRY_PICK_HEAD &&
296 test_cmp_rev anotherpick HEAD &&
297 git update-index --refresh &&
298 git diff-index --exit-code HEAD
301 test_expect_success 'revert --abort works, too' '
302 pristine_detach anotherpick &&
303 test_expect_code 1 git revert base..picked &&
304 git revert --abort &&
305 test_path_is_missing .git/sequencer &&
306 test_cmp_rev anotherpick HEAD
309 test_expect_success '--abort to cancel single revert' '
310 pristine_detach anotherpick &&
311 test_expect_code 1 git revert picked &&
312 git revert --abort &&
313 test_path_is_missing .git/sequencer &&
314 test_cmp_rev anotherpick HEAD &&
315 git update-index --refresh &&
316 git diff-index --exit-code HEAD
319 test_expect_success '--abort keeps unrelated change, easy case' '
320 pristine_detach unrelatedpick &&
321 echo changed >expect &&
322 test_expect_code 1 git cherry-pick picked..yetanotherpick &&
323 echo changed >unrelated &&
324 git cherry-pick --abort &&
325 test_cmp expect unrelated
328 test_expect_success '--abort refuses to clobber unrelated change, harder case' '
329 pristine_detach initial &&
330 echo changed >expect &&
331 test_expect_code 1 git cherry-pick base..anotherpick &&
332 echo changed >unrelated &&
333 test_must_fail git cherry-pick --abort &&
334 test_cmp expect unrelated &&
335 git rev-list HEAD >log &&
336 test_line_count = 2 log &&
337 test_must_fail git update-index --refresh &&
339 git checkout unrelated &&
340 git cherry-pick --abort &&
341 test_cmp_rev initial HEAD
344 test_expect_success 'cherry-pick still writes sequencer state when one commit is left' '
345 pristine_detach initial &&
346 test_expect_code 1 git cherry-pick base..picked &&
347 test_path_is_dir .git/sequencer &&
348 echo "resolved" >foo &&
349 git add foo &&
350 git commit &&
352 git rev-list HEAD |
353 git diff-tree --root --stdin |
354 sed "s/$OID_REGEX/OBJID/g"
355 } >actual &&
356 cat >expect <<-\EOF &&
357 OBJID
358 :100644 100644 OBJID OBJID M foo
359 OBJID
360 :100644 100644 OBJID OBJID M unrelated
361 OBJID
362 :000000 100644 OBJID OBJID A foo
363 :000000 100644 OBJID OBJID A unrelated
365 test_cmp expect actual
368 test_expect_success '--abort after last commit in sequence' '
369 pristine_detach initial &&
370 test_expect_code 1 git cherry-pick base..picked &&
371 git cherry-pick --abort &&
372 test_path_is_missing .git/sequencer &&
373 test_path_is_missing .git/CHERRY_PICK_HEAD &&
374 test_cmp_rev initial HEAD &&
375 git update-index --refresh &&
376 git diff-index --exit-code HEAD
379 test_expect_success 'cherry-pick does not implicitly stomp an existing operation' '
380 pristine_detach initial &&
381 test_expect_code 1 git cherry-pick base..anotherpick &&
382 test-tool chmtime --get .git/sequencer >expect &&
383 test_expect_code 128 git cherry-pick unrelatedpick &&
384 test-tool chmtime --get .git/sequencer >actual &&
385 test_cmp expect actual
388 test_expect_success '--continue complains when no cherry-pick is in progress' '
389 pristine_detach initial &&
390 test_expect_code 128 git cherry-pick --continue
393 test_expect_success '--continue complains when there are unresolved conflicts' '
394 pristine_detach initial &&
395 test_expect_code 1 git cherry-pick base..anotherpick &&
396 test_expect_code 128 git cherry-pick --continue
399 test_expect_success '--continue of single cherry-pick' '
400 pristine_detach initial &&
401 echo c >expect &&
402 test_must_fail git cherry-pick picked &&
403 echo c >foo &&
404 git add foo &&
405 git cherry-pick --continue &&
407 test_cmp expect foo &&
408 test_cmp_rev initial HEAD^ &&
409 git diff --exit-code HEAD &&
410 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
413 test_expect_success '--continue of single revert' '
414 pristine_detach initial &&
415 echo resolved >expect &&
416 echo "Revert \"picked\"" >expect.msg &&
417 test_must_fail git revert picked &&
418 echo resolved >foo &&
419 git add foo &&
420 git cherry-pick --continue &&
422 git diff --exit-code HEAD &&
423 test_cmp expect foo &&
424 test_cmp_rev initial HEAD^ &&
425 git diff-tree -s --pretty=tformat:%s HEAD >msg &&
426 test_cmp expect.msg msg &&
427 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
428 test_must_fail git rev-parse --verify REVERT_HEAD
431 test_expect_success '--continue after resolving conflicts' '
432 pristine_detach initial &&
433 echo d >expect &&
434 cat >expect.log <<-\EOF &&
435 OBJID
436 :100644 100644 OBJID OBJID M foo
437 OBJID
438 :100644 100644 OBJID OBJID M foo
439 OBJID
440 :100644 100644 OBJID OBJID M unrelated
441 OBJID
442 :000000 100644 OBJID OBJID A foo
443 :000000 100644 OBJID OBJID A unrelated
445 test_must_fail git cherry-pick base..anotherpick &&
446 echo c >foo &&
447 git add foo &&
448 git cherry-pick --continue &&
450 git rev-list HEAD |
451 git diff-tree --root --stdin |
452 sed "s/$OID_REGEX/OBJID/g"
453 } >actual.log &&
454 test_cmp expect foo &&
455 test_cmp expect.log actual.log
458 test_expect_success '--continue after resolving conflicts and committing' '
459 pristine_detach initial &&
460 test_expect_code 1 git cherry-pick base..anotherpick &&
461 echo "c" >foo &&
462 git add foo &&
463 git commit &&
464 git cherry-pick --continue &&
465 test_path_is_missing .git/sequencer &&
467 git rev-list HEAD |
468 git diff-tree --root --stdin |
469 sed "s/$OID_REGEX/OBJID/g"
470 } >actual &&
471 cat >expect <<-\EOF &&
472 OBJID
473 :100644 100644 OBJID OBJID M foo
474 OBJID
475 :100644 100644 OBJID OBJID M foo
476 OBJID
477 :100644 100644 OBJID OBJID M unrelated
478 OBJID
479 :000000 100644 OBJID OBJID A foo
480 :000000 100644 OBJID OBJID A unrelated
482 test_cmp expect actual
485 test_expect_success '--continue asks for help after resolving patch to nil' '
486 pristine_detach conflicting &&
487 test_must_fail git cherry-pick initial..picked &&
489 test_cmp_rev unrelatedpick CHERRY_PICK_HEAD &&
490 git checkout HEAD -- unrelated &&
491 test_must_fail git cherry-pick --continue 2>msg &&
492 test_i18ngrep "The previous cherry-pick is now empty" msg
495 test_expect_success 'follow advice and skip nil patch' '
496 pristine_detach conflicting &&
497 test_must_fail git cherry-pick initial..picked &&
499 git checkout HEAD -- unrelated &&
500 test_must_fail git cherry-pick --continue &&
501 git reset &&
502 git cherry-pick --continue &&
504 git rev-list initial..HEAD >commits &&
505 test_line_count = 3 commits
508 test_expect_success '--continue respects opts' '
509 pristine_detach initial &&
510 test_expect_code 1 git cherry-pick -x base..anotherpick &&
511 echo "c" >foo &&
512 git add foo &&
513 git commit &&
514 git cherry-pick --continue &&
515 test_path_is_missing .git/sequencer &&
516 git cat-file commit HEAD >anotherpick_msg &&
517 git cat-file commit HEAD~1 >picked_msg &&
518 git cat-file commit HEAD~2 >unrelatedpick_msg &&
519 git cat-file commit HEAD~3 >initial_msg &&
520 ! grep "cherry picked from" initial_msg &&
521 grep "cherry picked from" unrelatedpick_msg &&
522 grep "cherry picked from" picked_msg &&
523 grep "cherry picked from" anotherpick_msg
526 test_expect_success '--continue of single-pick respects -x' '
527 pristine_detach initial &&
528 test_must_fail git cherry-pick -x picked &&
529 echo c >foo &&
530 git add foo &&
531 git cherry-pick --continue &&
532 test_path_is_missing .git/sequencer &&
533 git cat-file commit HEAD >msg &&
534 grep "cherry picked from" msg
537 test_expect_success '--continue respects -x in first commit in multi-pick' '
538 pristine_detach initial &&
539 test_must_fail git cherry-pick -x picked anotherpick &&
540 echo c >foo &&
541 git add foo &&
542 git cherry-pick --continue &&
543 test_path_is_missing .git/sequencer &&
544 git cat-file commit HEAD^ >msg &&
545 picked=$(git rev-parse --verify picked) &&
546 grep "cherry picked from.*$picked" msg
549 test_expect_failure '--signoff is automatically propagated to resolved conflict' '
550 pristine_detach initial &&
551 test_expect_code 1 git cherry-pick --signoff base..anotherpick &&
552 echo "c" >foo &&
553 git add foo &&
554 git commit &&
555 git cherry-pick --continue &&
556 test_path_is_missing .git/sequencer &&
557 git cat-file commit HEAD >anotherpick_msg &&
558 git cat-file commit HEAD~1 >picked_msg &&
559 git cat-file commit HEAD~2 >unrelatedpick_msg &&
560 git cat-file commit HEAD~3 >initial_msg &&
561 ! grep "Signed-off-by:" initial_msg &&
562 grep "Signed-off-by:" unrelatedpick_msg &&
563 ! grep "Signed-off-by:" picked_msg &&
564 grep "Signed-off-by:" anotherpick_msg
567 test_expect_failure '--signoff dropped for implicit commit of resolution, multi-pick case' '
568 pristine_detach initial &&
569 test_must_fail git cherry-pick -s picked anotherpick &&
570 echo c >foo &&
571 git add foo &&
572 git cherry-pick --continue &&
574 git diff --exit-code HEAD &&
575 test_cmp_rev initial HEAD^^ &&
576 git cat-file commit HEAD^ >msg &&
577 ! grep Signed-off-by: msg
580 test_expect_failure 'sign-off needs to be reaffirmed after conflict resolution, single-pick case' '
581 pristine_detach initial &&
582 test_must_fail git cherry-pick -s picked &&
583 echo c >foo &&
584 git add foo &&
585 git cherry-pick --continue &&
587 git diff --exit-code HEAD &&
588 test_cmp_rev initial HEAD^ &&
589 git cat-file commit HEAD >msg &&
590 ! grep Signed-off-by: msg
593 test_expect_success 'malformed instruction sheet 1' '
594 pristine_detach initial &&
595 test_expect_code 1 git cherry-pick base..anotherpick &&
596 echo "resolved" >foo &&
597 git add foo &&
598 git commit &&
599 sed "s/pick /pick/" .git/sequencer/todo >new_sheet &&
600 cp new_sheet .git/sequencer/todo &&
601 test_expect_code 128 git cherry-pick --continue
604 test_expect_success 'malformed instruction sheet 2' '
605 pristine_detach initial &&
606 test_expect_code 1 git cherry-pick base..anotherpick &&
607 echo "resolved" >foo &&
608 git add foo &&
609 git commit &&
610 sed "s/pick/revert/" .git/sequencer/todo >new_sheet &&
611 cp new_sheet .git/sequencer/todo &&
612 test_expect_code 128 git cherry-pick --continue
615 test_expect_success 'empty commit set (no commits to walk)' '
616 pristine_detach initial &&
617 test_expect_code 128 git cherry-pick base..base
620 test_expect_success 'empty commit set (culled during walk)' '
621 pristine_detach initial &&
622 test_expect_code 128 git cherry-pick -2 --author=no.such.author base
625 test_expect_success 'malformed instruction sheet 3' '
626 pristine_detach initial &&
627 test_expect_code 1 git cherry-pick base..anotherpick &&
628 echo "resolved" >foo &&
629 git add foo &&
630 git commit &&
631 sed "s/pick \([0-9a-f]*\)/pick $_r10/" .git/sequencer/todo >new_sheet &&
632 cp new_sheet .git/sequencer/todo &&
633 test_expect_code 128 git cherry-pick --continue
636 test_expect_success 'instruction sheet, fat-fingers version' '
637 pristine_detach initial &&
638 test_expect_code 1 git cherry-pick base..anotherpick &&
639 echo "c" >foo &&
640 git add foo &&
641 git commit &&
642 sed "s/pick \([0-9a-f]*\)/pick \1 /" .git/sequencer/todo >new_sheet &&
643 cp new_sheet .git/sequencer/todo &&
644 git cherry-pick --continue
647 test_expect_success 'commit descriptions in insn sheet are optional' '
648 pristine_detach initial &&
649 test_expect_code 1 git cherry-pick base..anotherpick &&
650 echo "c" >foo &&
651 git add foo &&
652 git commit &&
653 cut -d" " -f1,2 .git/sequencer/todo >new_sheet &&
654 cp new_sheet .git/sequencer/todo &&
655 git cherry-pick --continue &&
656 test_path_is_missing .git/sequencer &&
657 git rev-list HEAD >commits &&
658 test_line_count = 4 commits
661 test_done