dir: fix treatment of negated pathspecs
[git/raj.git] / t / t3510-cherry-pick-sequence.sh
blob793bcc7fe3246e8fc375b8678bb99f7bc875a48c
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 &&
127 git cherry-pick --skip &&
128 test_cmp_rev dummy HEAD
131 test_expect_success 'skip a commit and check if rest of sequence is correct' '
132 pristine_detach initial &&
133 echo e >expect &&
134 cat >expect.log <<-EOF &&
135 OBJID
136 :100644 100644 OBJID OBJID M foo
137 OBJID
138 :100644 100644 OBJID OBJID M foo
139 OBJID
140 :100644 100644 OBJID OBJID M unrelated
141 OBJID
142 :000000 100644 OBJID OBJID A foo
143 :000000 100644 OBJID OBJID A unrelated
145 test_must_fail git cherry-pick base..yetanotherpick &&
146 test_must_fail git cherry-pick --skip &&
147 echo d >foo &&
148 git add foo &&
149 git cherry-pick --continue &&
151 git rev-list HEAD |
152 git diff-tree --root --stdin |
153 sed "s/$OID_REGEX/OBJID/g"
154 } >actual.log &&
155 test_cmp expect foo &&
156 test_cmp expect.log actual.log
159 test_expect_success 'check advice when we move HEAD by committing' '
160 pristine_detach initial &&
161 cat >expect <<-EOF &&
162 error: there is nothing to skip
163 hint: have you committed already?
164 hint: try "git cherry-pick --continue"
165 fatal: cherry-pick failed
167 test_must_fail git cherry-pick base..yetanotherpick &&
168 echo c >foo &&
169 git commit -a &&
170 test_path_is_missing .git/CHERRY_PICK_HEAD &&
171 test_must_fail git cherry-pick --skip 2>advice &&
172 test_i18ncmp expect advice
175 test_expect_success 'selectively advise --skip while launching another sequence' '
176 pristine_detach initial &&
177 cat >expect <<-EOF &&
178 error: cherry-pick is already in progress
179 hint: try "git cherry-pick (--continue | --skip | --abort | --quit)"
180 fatal: cherry-pick failed
182 test_must_fail git cherry-pick picked..yetanotherpick &&
183 test_must_fail git cherry-pick picked..yetanotherpick 2>advice &&
184 test_i18ncmp expect advice &&
185 cat >expect <<-EOF &&
186 error: cherry-pick is already in progress
187 hint: try "git cherry-pick (--continue | --abort | --quit)"
188 fatal: cherry-pick failed
190 git reset --merge &&
191 test_must_fail git cherry-pick picked..yetanotherpick 2>advice &&
192 test_i18ncmp expect advice
195 test_expect_success 'allow skipping commit but not abort for a new history' '
196 pristine_detach initial &&
197 cat >expect <<-EOF &&
198 error: cannot abort from a branch yet to be born
199 fatal: cherry-pick failed
201 git checkout --orphan new_disconnected &&
202 git reset --hard &&
203 test_must_fail git cherry-pick anotherpick &&
204 test_must_fail git cherry-pick --abort 2>advice &&
205 git cherry-pick --skip &&
206 test_i18ncmp expect advice
209 test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' '
210 pristine_detach initial &&
211 git rm --cached unrelated &&
212 git commit -m "untrack unrelated" &&
213 test_must_fail git cherry-pick initial base &&
214 test_path_is_missing .git/CHERRY_PICK_HEAD &&
215 git cherry-pick --skip
218 test_expect_success '--quit does not complain when no cherry-pick is in progress' '
219 pristine_detach initial &&
220 git cherry-pick --quit
223 test_expect_success '--abort requires cherry-pick in progress' '
224 pristine_detach initial &&
225 test_must_fail git cherry-pick --abort
228 test_expect_success '--quit cleans up sequencer state' '
229 pristine_detach initial &&
230 test_expect_code 1 git cherry-pick base..picked &&
231 git cherry-pick --quit &&
232 test_path_is_missing .git/sequencer &&
233 test_path_is_missing .git/CHERRY_PICK_HEAD
236 test_expect_success '--quit keeps HEAD and conflicted index intact' '
237 pristine_detach initial &&
238 cat >expect <<-\EOF &&
239 OBJID
240 :100644 100644 OBJID OBJID M unrelated
241 OBJID
242 :000000 100644 OBJID OBJID A foo
243 :000000 100644 OBJID OBJID A unrelated
245 test_expect_code 1 git cherry-pick base..picked &&
246 git cherry-pick --quit &&
247 test_path_is_missing .git/sequencer &&
248 test_must_fail git update-index --refresh &&
250 git rev-list HEAD |
251 git diff-tree --root --stdin |
252 sed "s/$OID_REGEX/OBJID/g"
253 } >actual &&
254 test_cmp expect actual
257 test_expect_success '--abort to cancel multiple cherry-pick' '
258 pristine_detach initial &&
259 test_expect_code 1 git cherry-pick base..anotherpick &&
260 git cherry-pick --abort &&
261 test_path_is_missing .git/sequencer &&
262 test_path_is_missing .git/CHERRY_PICK_HEAD &&
263 test_cmp_rev initial HEAD &&
264 git update-index --refresh &&
265 git diff-index --exit-code HEAD
268 test_expect_success '--abort to cancel single cherry-pick' '
269 pristine_detach initial &&
270 test_expect_code 1 git cherry-pick picked &&
271 git cherry-pick --abort &&
272 test_path_is_missing .git/sequencer &&
273 test_path_is_missing .git/CHERRY_PICK_HEAD &&
274 test_cmp_rev initial HEAD &&
275 git update-index --refresh &&
276 git diff-index --exit-code HEAD
279 test_expect_success '--abort does not unsafely change HEAD' '
280 pristine_detach initial &&
281 test_must_fail git cherry-pick picked anotherpick &&
282 git reset --hard base &&
283 test_must_fail git cherry-pick picked anotherpick &&
284 git cherry-pick --abort 2>actual &&
285 test_i18ngrep "You seem to have moved HEAD" actual &&
286 test_cmp_rev base HEAD
289 test_expect_success 'cherry-pick --abort to cancel multiple revert' '
290 pristine_detach anotherpick &&
291 test_expect_code 1 git revert base..picked &&
292 git cherry-pick --abort &&
293 test_path_is_missing .git/sequencer &&
294 test_path_is_missing .git/CHERRY_PICK_HEAD &&
295 test_cmp_rev anotherpick HEAD &&
296 git update-index --refresh &&
297 git diff-index --exit-code HEAD
300 test_expect_success 'revert --abort works, too' '
301 pristine_detach anotherpick &&
302 test_expect_code 1 git revert base..picked &&
303 git revert --abort &&
304 test_path_is_missing .git/sequencer &&
305 test_cmp_rev anotherpick HEAD
308 test_expect_success '--abort to cancel single revert' '
309 pristine_detach anotherpick &&
310 test_expect_code 1 git revert picked &&
311 git revert --abort &&
312 test_path_is_missing .git/sequencer &&
313 test_cmp_rev anotherpick HEAD &&
314 git update-index --refresh &&
315 git diff-index --exit-code HEAD
318 test_expect_success '--abort keeps unrelated change, easy case' '
319 pristine_detach unrelatedpick &&
320 echo changed >expect &&
321 test_expect_code 1 git cherry-pick picked..yetanotherpick &&
322 echo changed >unrelated &&
323 git cherry-pick --abort &&
324 test_cmp expect unrelated
327 test_expect_success '--abort refuses to clobber unrelated change, harder case' '
328 pristine_detach initial &&
329 echo changed >expect &&
330 test_expect_code 1 git cherry-pick base..anotherpick &&
331 echo changed >unrelated &&
332 test_must_fail git cherry-pick --abort &&
333 test_cmp expect unrelated &&
334 git rev-list HEAD >log &&
335 test_line_count = 2 log &&
336 test_must_fail git update-index --refresh &&
338 git checkout unrelated &&
339 git cherry-pick --abort &&
340 test_cmp_rev initial HEAD
343 test_expect_success 'cherry-pick still writes sequencer state when one commit is left' '
344 pristine_detach initial &&
345 test_expect_code 1 git cherry-pick base..picked &&
346 test_path_is_dir .git/sequencer &&
347 echo "resolved" >foo &&
348 git add foo &&
349 git commit &&
351 git rev-list HEAD |
352 git diff-tree --root --stdin |
353 sed "s/$OID_REGEX/OBJID/g"
354 } >actual &&
355 cat >expect <<-\EOF &&
356 OBJID
357 :100644 100644 OBJID OBJID M foo
358 OBJID
359 :100644 100644 OBJID OBJID M unrelated
360 OBJID
361 :000000 100644 OBJID OBJID A foo
362 :000000 100644 OBJID OBJID A unrelated
364 test_cmp expect actual
367 test_expect_success '--abort after last commit in sequence' '
368 pristine_detach initial &&
369 test_expect_code 1 git cherry-pick base..picked &&
370 git cherry-pick --abort &&
371 test_path_is_missing .git/sequencer &&
372 test_path_is_missing .git/CHERRY_PICK_HEAD &&
373 test_cmp_rev initial HEAD &&
374 git update-index --refresh &&
375 git diff-index --exit-code HEAD
378 test_expect_success 'cherry-pick does not implicitly stomp an existing operation' '
379 pristine_detach initial &&
380 test_expect_code 1 git cherry-pick base..anotherpick &&
381 test-tool chmtime --get .git/sequencer >expect &&
382 test_expect_code 128 git cherry-pick unrelatedpick &&
383 test-tool chmtime --get .git/sequencer >actual &&
384 test_cmp expect actual
387 test_expect_success '--continue complains when no cherry-pick is in progress' '
388 pristine_detach initial &&
389 test_expect_code 128 git cherry-pick --continue
392 test_expect_success '--continue complains when there are unresolved conflicts' '
393 pristine_detach initial &&
394 test_expect_code 1 git cherry-pick base..anotherpick &&
395 test_expect_code 128 git cherry-pick --continue
398 test_expect_success '--continue of single cherry-pick' '
399 pristine_detach initial &&
400 echo c >expect &&
401 test_must_fail git cherry-pick picked &&
402 echo c >foo &&
403 git add foo &&
404 git cherry-pick --continue &&
406 test_cmp expect foo &&
407 test_cmp_rev initial HEAD^ &&
408 git diff --exit-code HEAD &&
409 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
412 test_expect_success '--continue of single revert' '
413 pristine_detach initial &&
414 echo resolved >expect &&
415 echo "Revert \"picked\"" >expect.msg &&
416 test_must_fail git revert picked &&
417 echo resolved >foo &&
418 git add foo &&
419 git cherry-pick --continue &&
421 git diff --exit-code HEAD &&
422 test_cmp expect foo &&
423 test_cmp_rev initial HEAD^ &&
424 git diff-tree -s --pretty=tformat:%s HEAD >msg &&
425 test_cmp expect.msg msg &&
426 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
427 test_must_fail git rev-parse --verify REVERT_HEAD
430 test_expect_success '--continue after resolving conflicts' '
431 pristine_detach initial &&
432 echo d >expect &&
433 cat >expect.log <<-\EOF &&
434 OBJID
435 :100644 100644 OBJID OBJID M foo
436 OBJID
437 :100644 100644 OBJID OBJID M foo
438 OBJID
439 :100644 100644 OBJID OBJID M unrelated
440 OBJID
441 :000000 100644 OBJID OBJID A foo
442 :000000 100644 OBJID OBJID A unrelated
444 test_must_fail git cherry-pick base..anotherpick &&
445 echo c >foo &&
446 git add foo &&
447 git cherry-pick --continue &&
449 git rev-list HEAD |
450 git diff-tree --root --stdin |
451 sed "s/$OID_REGEX/OBJID/g"
452 } >actual.log &&
453 test_cmp expect foo &&
454 test_cmp expect.log actual.log
457 test_expect_success '--continue after resolving conflicts and committing' '
458 pristine_detach initial &&
459 test_expect_code 1 git cherry-pick base..anotherpick &&
460 echo "c" >foo &&
461 git add foo &&
462 git commit &&
463 git cherry-pick --continue &&
464 test_path_is_missing .git/sequencer &&
466 git rev-list HEAD |
467 git diff-tree --root --stdin |
468 sed "s/$OID_REGEX/OBJID/g"
469 } >actual &&
470 cat >expect <<-\EOF &&
471 OBJID
472 :100644 100644 OBJID OBJID M foo
473 OBJID
474 :100644 100644 OBJID OBJID M foo
475 OBJID
476 :100644 100644 OBJID OBJID M unrelated
477 OBJID
478 :000000 100644 OBJID OBJID A foo
479 :000000 100644 OBJID OBJID A unrelated
481 test_cmp expect actual
484 test_expect_success '--continue asks for help after resolving patch to nil' '
485 pristine_detach conflicting &&
486 test_must_fail git cherry-pick initial..picked &&
488 test_cmp_rev unrelatedpick CHERRY_PICK_HEAD &&
489 git checkout HEAD -- unrelated &&
490 test_must_fail git cherry-pick --continue 2>msg &&
491 test_i18ngrep "The previous cherry-pick is now empty" msg
494 test_expect_success 'follow advice and skip nil patch' '
495 pristine_detach conflicting &&
496 test_must_fail git cherry-pick initial..picked &&
498 git checkout HEAD -- unrelated &&
499 test_must_fail git cherry-pick --continue &&
500 git reset &&
501 git cherry-pick --continue &&
503 git rev-list initial..HEAD >commits &&
504 test_line_count = 3 commits
507 test_expect_success '--continue respects opts' '
508 pristine_detach initial &&
509 test_expect_code 1 git cherry-pick -x base..anotherpick &&
510 echo "c" >foo &&
511 git add foo &&
512 git commit &&
513 git cherry-pick --continue &&
514 test_path_is_missing .git/sequencer &&
515 git cat-file commit HEAD >anotherpick_msg &&
516 git cat-file commit HEAD~1 >picked_msg &&
517 git cat-file commit HEAD~2 >unrelatedpick_msg &&
518 git cat-file commit HEAD~3 >initial_msg &&
519 ! grep "cherry picked from" initial_msg &&
520 grep "cherry picked from" unrelatedpick_msg &&
521 grep "cherry picked from" picked_msg &&
522 grep "cherry picked from" anotherpick_msg
525 test_expect_success '--continue of single-pick respects -x' '
526 pristine_detach initial &&
527 test_must_fail git cherry-pick -x picked &&
528 echo c >foo &&
529 git add foo &&
530 git cherry-pick --continue &&
531 test_path_is_missing .git/sequencer &&
532 git cat-file commit HEAD >msg &&
533 grep "cherry picked from" msg
536 test_expect_success '--continue respects -x in first commit in multi-pick' '
537 pristine_detach initial &&
538 test_must_fail git cherry-pick -x picked anotherpick &&
539 echo c >foo &&
540 git add foo &&
541 git cherry-pick --continue &&
542 test_path_is_missing .git/sequencer &&
543 git cat-file commit HEAD^ >msg &&
544 picked=$(git rev-parse --verify picked) &&
545 grep "cherry picked from.*$picked" msg
548 test_expect_failure '--signoff is automatically propagated to resolved conflict' '
549 pristine_detach initial &&
550 test_expect_code 1 git cherry-pick --signoff base..anotherpick &&
551 echo "c" >foo &&
552 git add foo &&
553 git commit &&
554 git cherry-pick --continue &&
555 test_path_is_missing .git/sequencer &&
556 git cat-file commit HEAD >anotherpick_msg &&
557 git cat-file commit HEAD~1 >picked_msg &&
558 git cat-file commit HEAD~2 >unrelatedpick_msg &&
559 git cat-file commit HEAD~3 >initial_msg &&
560 ! grep "Signed-off-by:" initial_msg &&
561 grep "Signed-off-by:" unrelatedpick_msg &&
562 ! grep "Signed-off-by:" picked_msg &&
563 grep "Signed-off-by:" anotherpick_msg
566 test_expect_failure '--signoff dropped for implicit commit of resolution, multi-pick case' '
567 pristine_detach initial &&
568 test_must_fail git cherry-pick -s picked anotherpick &&
569 echo c >foo &&
570 git add foo &&
571 git cherry-pick --continue &&
573 git diff --exit-code HEAD &&
574 test_cmp_rev initial HEAD^^ &&
575 git cat-file commit HEAD^ >msg &&
576 ! grep Signed-off-by: msg
579 test_expect_failure 'sign-off needs to be reaffirmed after conflict resolution, single-pick case' '
580 pristine_detach initial &&
581 test_must_fail git cherry-pick -s picked &&
582 echo c >foo &&
583 git add foo &&
584 git cherry-pick --continue &&
586 git diff --exit-code HEAD &&
587 test_cmp_rev initial HEAD^ &&
588 git cat-file commit HEAD >msg &&
589 ! grep Signed-off-by: msg
592 test_expect_success 'malformed instruction sheet 1' '
593 pristine_detach initial &&
594 test_expect_code 1 git cherry-pick base..anotherpick &&
595 echo "resolved" >foo &&
596 git add foo &&
597 git commit &&
598 sed "s/pick /pick/" .git/sequencer/todo >new_sheet &&
599 cp new_sheet .git/sequencer/todo &&
600 test_expect_code 128 git cherry-pick --continue
603 test_expect_success 'malformed instruction sheet 2' '
604 pristine_detach initial &&
605 test_expect_code 1 git cherry-pick base..anotherpick &&
606 echo "resolved" >foo &&
607 git add foo &&
608 git commit &&
609 sed "s/pick/revert/" .git/sequencer/todo >new_sheet &&
610 cp new_sheet .git/sequencer/todo &&
611 test_expect_code 128 git cherry-pick --continue
614 test_expect_success 'empty commit set (no commits to walk)' '
615 pristine_detach initial &&
616 test_expect_code 128 git cherry-pick base..base
619 test_expect_success 'empty commit set (culled during walk)' '
620 pristine_detach initial &&
621 test_expect_code 128 git cherry-pick -2 --author=no.such.author base
624 test_expect_success 'malformed instruction sheet 3' '
625 pristine_detach initial &&
626 test_expect_code 1 git cherry-pick base..anotherpick &&
627 echo "resolved" >foo &&
628 git add foo &&
629 git commit &&
630 sed "s/pick \([0-9a-f]*\)/pick $_r10/" .git/sequencer/todo >new_sheet &&
631 cp new_sheet .git/sequencer/todo &&
632 test_expect_code 128 git cherry-pick --continue
635 test_expect_success 'instruction sheet, fat-fingers version' '
636 pristine_detach initial &&
637 test_expect_code 1 git cherry-pick base..anotherpick &&
638 echo "c" >foo &&
639 git add foo &&
640 git commit &&
641 sed "s/pick \([0-9a-f]*\)/pick \1 /" .git/sequencer/todo >new_sheet &&
642 cp new_sheet .git/sequencer/todo &&
643 git cherry-pick --continue
646 test_expect_success 'commit descriptions in insn sheet are optional' '
647 pristine_detach initial &&
648 test_expect_code 1 git cherry-pick base..anotherpick &&
649 echo "c" >foo &&
650 git add foo &&
651 git commit &&
652 cut -d" " -f1,2 .git/sequencer/todo >new_sheet &&
653 cp new_sheet .git/sequencer/todo &&
654 git cherry-pick --continue &&
655 test_path_is_missing .git/sequencer &&
656 git rev-list HEAD >commits &&
657 test_line_count = 4 commits
660 test_done