Merge branch 'db/show-ref-head'
[git/mingw.git] / t / t3404-rebase-interactive.sh
blob49ccb38f8856e6e5fa00961c6e9117f94c6ae233
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='git rebase interactive
8 This test runs git rebase "interactively", by faking an edit, and verifies
9 that the result still makes sense.
11 Initial setup:
13 one - two - three - four (conflict-branch)
15 A - B - C - D - E (master)
16 | \
17 | F - G - H (branch1)
18 | \
19 |\ I (branch2)
20 | \
21 | J - K - L - M (no-conflict-branch)
23 N - O - P (no-ff-branch)
25 where A, B, D and G all touch file1, and one, two, three, four all
26 touch file "conflict".
28 . ./test-lib.sh
30 . "$TEST_DIRECTORY"/lib-rebase.sh
32 set_fake_editor
34 # WARNING: Modifications to the initial repository can change the SHA ID used
35 # in the expect2 file for the 'stop on conflicting pick' test.
37 test_expect_success 'setup' '
38 test_commit A file1 &&
39 test_commit B file1 &&
40 test_commit C file2 &&
41 test_commit D file1 &&
42 test_commit E file3 &&
43 git checkout -b branch1 A &&
44 test_commit F file4 &&
45 test_commit G file1 &&
46 test_commit H file5 &&
47 git checkout -b branch2 F &&
48 test_commit I file6 &&
49 git checkout -b conflict-branch A &&
50 test_commit one conflict &&
51 test_commit two conflict &&
52 test_commit three conflict &&
53 test_commit four conflict &&
54 git checkout -b no-conflict-branch A &&
55 test_commit J fileJ &&
56 test_commit K fileK &&
57 test_commit L fileL &&
58 test_commit M fileM &&
59 git checkout -b no-ff-branch A &&
60 test_commit N fileN &&
61 test_commit O fileO &&
62 test_commit P fileP
65 # "exec" commands are ran with the user shell by default, but this may
66 # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work
67 # to create a file. Unseting SHELL avoids such non-portable behavior
68 # in tests. It must be exported for it to take effect where needed.
69 SHELL=
70 export SHELL
72 test_expect_success 'rebase -i with the exec command' '
73 git checkout master &&
75 FAKE_LINES="1 exec_>touch-one
76 2 exec_>touch-two exec_false exec_>touch-three
77 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
78 export FAKE_LINES &&
79 test_must_fail git rebase -i A
80 ) &&
81 test_path_is_file touch-one &&
82 test_path_is_file touch-two &&
83 test_path_is_missing touch-three " (should have stopped before)" &&
84 test_cmp_rev C HEAD &&
85 git rebase --continue &&
86 test_path_is_file touch-three &&
87 test_path_is_file "touch-file name with spaces" &&
88 test_path_is_file touch-after-semicolon &&
89 test_cmp_rev master HEAD &&
90 rm -f touch-*
93 test_expect_success 'rebase -i with the exec command runs from tree root' '
94 git checkout master &&
95 mkdir subdir && (cd subdir &&
96 FAKE_LINES="1 exec_>touch-subdir" \
97 git rebase -i HEAD^
98 ) &&
99 test_path_is_file touch-subdir &&
100 rm -fr subdir
103 test_expect_success 'rebase -i with the exec command checks tree cleanness' '
104 git checkout master &&
106 FAKE_LINES="exec_echo_foo_>file1 1" &&
107 export FAKE_LINES &&
108 test_must_fail git rebase -i HEAD^
109 ) &&
110 test_cmp_rev master^ HEAD &&
111 git reset --hard &&
112 git rebase --continue
115 test_expect_success 'rebase -i with exec of inexistent command' '
116 git checkout master &&
117 test_when_finished "git rebase --abort" &&
119 FAKE_LINES="exec_this-command-does-not-exist 1" &&
120 export FAKE_LINES &&
121 test_must_fail git rebase -i HEAD^ >actual 2>&1
122 ) &&
123 ! grep "Maybe git-rebase is broken" actual
126 test_expect_success 'no changes are a nop' '
127 git checkout branch2 &&
128 git rebase -i F &&
129 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
130 test $(git rev-parse I) = $(git rev-parse HEAD)
133 test_expect_success 'test the [branch] option' '
134 git checkout -b dead-end &&
135 git rm file6 &&
136 git commit -m "stop here" &&
137 git rebase -i F branch2 &&
138 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
139 test $(git rev-parse I) = $(git rev-parse branch2) &&
140 test $(git rev-parse I) = $(git rev-parse HEAD)
143 test_expect_success 'test --onto <branch>' '
144 git checkout -b test-onto branch2 &&
145 git rebase -i --onto branch1 F &&
146 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
147 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
148 test $(git rev-parse I) = $(git rev-parse branch2)
151 test_expect_success 'rebase on top of a non-conflicting commit' '
152 git checkout branch1 &&
153 git tag original-branch1 &&
154 git rebase -i branch2 &&
155 test file6 = $(git diff --name-only original-branch1) &&
156 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
157 test $(git rev-parse I) = $(git rev-parse branch2) &&
158 test $(git rev-parse I) = $(git rev-parse HEAD~2)
161 test_expect_success 'reflog for the branch shows state before rebase' '
162 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
165 test_expect_success 'exchange two commits' '
166 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
167 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
168 test G = $(git cat-file commit HEAD | sed -ne \$p)
171 cat > expect << EOF
172 diff --git a/file1 b/file1
173 index f70f10e..fd79235 100644
174 --- a/file1
175 +++ b/file1
176 @@ -1 +1 @@
181 cat > expect2 << EOF
182 <<<<<<< HEAD
184 =======
186 >>>>>>> 5d18e54... G
189 test_expect_success 'stop on conflicting pick' '
190 git tag new-branch1 &&
191 test_must_fail git rebase -i master &&
192 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
193 test_cmp expect .git/rebase-merge/patch &&
194 test_cmp expect2 file1 &&
195 test "$(git diff --name-status |
196 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
197 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
198 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
201 test_expect_success 'abort' '
202 git rebase --abort &&
203 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
204 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
205 test_path_is_missing .git/rebase-merge
208 test_expect_success 'abort with error when new base cannot be checked out' '
209 git rm --cached file1 &&
210 git commit -m "remove file in base" &&
211 test_must_fail git rebase -i master > output 2>&1 &&
212 grep "The following untracked working tree files would be overwritten by checkout:" \
213 output &&
214 grep "file1" output &&
215 test_path_is_missing .git/rebase-merge &&
216 git reset --hard HEAD^
219 test_expect_success 'retain authorship' '
220 echo A > file7 &&
221 git add file7 &&
222 test_tick &&
223 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
224 git tag twerp &&
225 git rebase -i --onto master HEAD^ &&
226 git show HEAD | grep "^Author: Twerp Snog"
229 test_expect_success 'squash' '
230 git reset --hard twerp &&
231 echo B > file7 &&
232 test_tick &&
233 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
234 echo "******************************" &&
235 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
236 git rebase -i --onto master HEAD~2 &&
237 test B = $(cat file7) &&
238 test $(git rev-parse HEAD^) = $(git rev-parse master)
241 test_expect_success 'retain authorship when squashing' '
242 git show HEAD | grep "^Author: Twerp Snog"
245 test_expect_success '-p handles "no changes" gracefully' '
246 HEAD=$(git rev-parse HEAD) &&
247 git rebase -i -p HEAD^ &&
248 git update-index --refresh &&
249 git diff-files --quiet &&
250 git diff-index --quiet --cached HEAD -- &&
251 test $HEAD = $(git rev-parse HEAD)
254 test_expect_failure 'exchange two commits with -p' '
255 git checkout H &&
256 FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
257 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
258 test G = $(git cat-file commit HEAD | sed -ne \$p)
261 test_expect_success 'preserve merges with -p' '
262 git checkout -b to-be-preserved master^ &&
263 : > unrelated-file &&
264 git add unrelated-file &&
265 test_tick &&
266 git commit -m "unrelated" &&
267 git checkout -b another-branch master &&
268 echo B > file1 &&
269 test_tick &&
270 git commit -m J file1 &&
271 test_tick &&
272 git merge to-be-preserved &&
273 echo C > file1 &&
274 test_tick &&
275 git commit -m K file1 &&
276 echo D > file1 &&
277 test_tick &&
278 git commit -m L1 file1 &&
279 git checkout HEAD^ &&
280 echo 1 > unrelated-file &&
281 test_tick &&
282 git commit -m L2 unrelated-file &&
283 test_tick &&
284 git merge another-branch &&
285 echo E > file1 &&
286 test_tick &&
287 git commit -m M file1 &&
288 git checkout -b to-be-rebased &&
289 test_tick &&
290 git rebase -i -p --onto branch1 master &&
291 git update-index --refresh &&
292 git diff-files --quiet &&
293 git diff-index --quiet --cached HEAD -- &&
294 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
295 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
296 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
297 test $(git show HEAD~5:file1) = B &&
298 test $(git show HEAD~3:file1) = C &&
299 test $(git show HEAD:file1) = E &&
300 test $(git show HEAD:unrelated-file) = 1
303 test_expect_success 'edit ancestor with -p' '
304 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
305 echo 2 > unrelated-file &&
306 test_tick &&
307 git commit -m L2-modified --amend unrelated-file &&
308 git rebase --continue &&
309 git update-index --refresh &&
310 git diff-files --quiet &&
311 git diff-index --quiet --cached HEAD -- &&
312 test $(git show HEAD:unrelated-file) = 2
315 test_expect_success '--continue tries to commit' '
316 test_tick &&
317 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
318 echo resolved > file1 &&
319 git add file1 &&
320 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
321 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
322 git show HEAD | grep chouette
325 test_expect_success 'verbose flag is heeded, even after --continue' '
326 git reset --hard master@{1} &&
327 test_tick &&
328 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
329 echo resolved > file1 &&
330 git add file1 &&
331 git rebase --continue > output &&
332 grep "^ file1 | 2 +-$" output
335 test_expect_success 'multi-squash only fires up editor once' '
336 base=$(git rev-parse HEAD~4) &&
337 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
338 EXPECT_HEADER_COUNT=4 \
339 git rebase -i $base &&
340 test $base = $(git rev-parse HEAD^) &&
341 test 1 = $(git show | grep ONCE | wc -l)
344 test_expect_success 'multi-fixup does not fire up editor' '
345 git checkout -b multi-fixup E &&
346 base=$(git rev-parse HEAD~4) &&
347 FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
348 git rebase -i $base &&
349 test $base = $(git rev-parse HEAD^) &&
350 test 0 = $(git show | grep NEVER | wc -l) &&
351 git checkout to-be-rebased &&
352 git branch -D multi-fixup
355 test_expect_success 'commit message used after conflict' '
356 git checkout -b conflict-fixup conflict-branch &&
357 base=$(git rev-parse HEAD~4) &&
359 FAKE_LINES="1 fixup 3 fixup 4" &&
360 export FAKE_LINES &&
361 test_must_fail git rebase -i $base
362 ) &&
363 echo three > conflict &&
364 git add conflict &&
365 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
366 git rebase --continue &&
367 test $base = $(git rev-parse HEAD^) &&
368 test 1 = $(git show | grep ONCE | wc -l) &&
369 git checkout to-be-rebased &&
370 git branch -D conflict-fixup
373 test_expect_success 'commit message retained after conflict' '
374 git checkout -b conflict-squash conflict-branch &&
375 base=$(git rev-parse HEAD~4) &&
377 FAKE_LINES="1 fixup 3 squash 4" &&
378 export FAKE_LINES &&
379 test_must_fail git rebase -i $base
380 ) &&
381 echo three > conflict &&
382 git add conflict &&
383 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
384 git rebase --continue &&
385 test $base = $(git rev-parse HEAD^) &&
386 test 2 = $(git show | grep TWICE | wc -l) &&
387 git checkout to-be-rebased &&
388 git branch -D conflict-squash
391 cat > expect-squash-fixup << EOF
396 ONCE
399 test_expect_success 'squash and fixup generate correct log messages' '
400 git checkout -b squash-fixup E &&
401 base=$(git rev-parse HEAD~4) &&
402 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
403 EXPECT_HEADER_COUNT=4 \
404 git rebase -i $base &&
405 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
406 test_cmp expect-squash-fixup actual-squash-fixup &&
407 git checkout to-be-rebased &&
408 git branch -D squash-fixup
411 test_expect_success 'squash ignores comments' '
412 git checkout -b skip-comments E &&
413 base=$(git rev-parse HEAD~4) &&
414 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
415 EXPECT_HEADER_COUNT=4 \
416 git rebase -i $base &&
417 test $base = $(git rev-parse HEAD^) &&
418 test 1 = $(git show | grep ONCE | wc -l) &&
419 git checkout to-be-rebased &&
420 git branch -D skip-comments
423 test_expect_success 'squash ignores blank lines' '
424 git checkout -b skip-blank-lines E &&
425 base=$(git rev-parse HEAD~4) &&
426 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
427 EXPECT_HEADER_COUNT=4 \
428 git rebase -i $base &&
429 test $base = $(git rev-parse HEAD^) &&
430 test 1 = $(git show | grep ONCE | wc -l) &&
431 git checkout to-be-rebased &&
432 git branch -D skip-blank-lines
435 test_expect_success 'squash works as expected' '
436 git checkout -b squash-works no-conflict-branch &&
437 one=$(git rev-parse HEAD~3) &&
438 FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
439 git rebase -i HEAD~3 &&
440 test $one = $(git rev-parse HEAD~2)
443 test_expect_success 'interrupted squash works as expected' '
444 git checkout -b interrupted-squash conflict-branch &&
445 one=$(git rev-parse HEAD~3) &&
447 FAKE_LINES="1 squash 3 2" &&
448 export FAKE_LINES &&
449 test_must_fail git rebase -i HEAD~3
450 ) &&
451 (echo one; echo two; echo four) > conflict &&
452 git add conflict &&
453 test_must_fail git rebase --continue &&
454 echo resolved > conflict &&
455 git add conflict &&
456 git rebase --continue &&
457 test $one = $(git rev-parse HEAD~2)
460 test_expect_success 'interrupted squash works as expected (case 2)' '
461 git checkout -b interrupted-squash2 conflict-branch &&
462 one=$(git rev-parse HEAD~3) &&
464 FAKE_LINES="3 squash 1 2" &&
465 export FAKE_LINES &&
466 test_must_fail git rebase -i HEAD~3
467 ) &&
468 (echo one; echo four) > conflict &&
469 git add conflict &&
470 test_must_fail git rebase --continue &&
471 (echo one; echo two; echo four) > conflict &&
472 git add conflict &&
473 test_must_fail git rebase --continue &&
474 echo resolved > conflict &&
475 git add conflict &&
476 git rebase --continue &&
477 test $one = $(git rev-parse HEAD~2)
480 test_expect_success '--continue tries to commit, even for "edit"' '
481 echo unrelated > file7 &&
482 git add file7 &&
483 test_tick &&
484 git commit -m "unrelated change" &&
485 parent=$(git rev-parse HEAD^) &&
486 test_tick &&
487 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
488 echo edited > file7 &&
489 git add file7 &&
490 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
491 test edited = $(git show HEAD:file7) &&
492 git show HEAD | grep chouette &&
493 test $parent = $(git rev-parse HEAD^)
496 test_expect_success 'aborted --continue does not squash commits after "edit"' '
497 old=$(git rev-parse HEAD) &&
498 test_tick &&
499 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
500 echo "edited again" > file7 &&
501 git add file7 &&
503 FAKE_COMMIT_MESSAGE=" " &&
504 export FAKE_COMMIT_MESSAGE &&
505 test_must_fail git rebase --continue
506 ) &&
507 test $old = $(git rev-parse HEAD) &&
508 git rebase --abort
511 test_expect_success 'auto-amend only edited commits after "edit"' '
512 test_tick &&
513 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
514 echo "edited again" > file7 &&
515 git add file7 &&
516 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
517 echo "and again" > file7 &&
518 git add file7 &&
519 test_tick &&
521 FAKE_COMMIT_MESSAGE="and again" &&
522 export FAKE_COMMIT_MESSAGE &&
523 test_must_fail git rebase --continue
524 ) &&
525 git rebase --abort
528 test_expect_success 'clean error after failed "exec"' '
529 test_tick &&
530 test_when_finished "git rebase --abort || :" &&
532 FAKE_LINES="1 exec_false" &&
533 export FAKE_LINES &&
534 test_must_fail git rebase -i HEAD^
535 ) &&
536 echo "edited again" > file7 &&
537 git add file7 &&
538 test_must_fail git rebase --continue 2>error &&
539 grep "You have staged changes in your working tree." error
542 test_expect_success 'rebase a detached HEAD' '
543 grandparent=$(git rev-parse HEAD~2) &&
544 git checkout $(git rev-parse HEAD) &&
545 test_tick &&
546 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
547 test $grandparent = $(git rev-parse HEAD~2)
550 test_expect_success 'rebase a commit violating pre-commit' '
552 mkdir -p .git/hooks &&
553 PRE_COMMIT=.git/hooks/pre-commit &&
554 echo "#!/bin/sh" > $PRE_COMMIT &&
555 echo "test -z \"\$(git diff --cached --check)\"" >> $PRE_COMMIT &&
556 chmod a+x $PRE_COMMIT &&
557 echo "monde! " >> file1 &&
558 test_tick &&
559 test_must_fail git commit -m doesnt-verify file1 &&
560 git commit -m doesnt-verify --no-verify file1 &&
561 test_tick &&
562 FAKE_LINES=2 git rebase -i HEAD~2
566 test_expect_success 'rebase with a file named HEAD in worktree' '
568 rm -fr .git/hooks &&
569 git reset --hard &&
570 git checkout -b branch3 A &&
573 GIT_AUTHOR_NAME="Squashed Away" &&
574 export GIT_AUTHOR_NAME &&
575 >HEAD &&
576 git add HEAD &&
577 git commit -m "Add head" &&
578 >BODY &&
579 git add BODY &&
580 git commit -m "Add body"
581 ) &&
583 FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
584 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
588 test_expect_success 'do "noop" when there is nothing to cherry-pick' '
590 git checkout -b branch4 HEAD &&
591 GIT_EDITOR=: git commit --amend \
592 --author="Somebody else <somebody@else.com>" &&
593 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
594 git rebase -i branch3 &&
595 test $(git rev-parse branch3) = $(git rev-parse branch4)
599 test_expect_success 'submodule rebase setup' '
600 git checkout A &&
601 mkdir sub &&
603 cd sub && git init && >elif &&
604 git add elif && git commit -m "submodule initial"
605 ) &&
606 echo 1 >file1 &&
607 git add file1 sub &&
608 test_tick &&
609 git commit -m "One" &&
610 echo 2 >file1 &&
611 test_tick &&
612 git commit -a -m "Two" &&
614 cd sub && echo 3 >elif &&
615 git commit -a -m "submodule second"
616 ) &&
617 test_tick &&
618 git commit -a -m "Three changes submodule"
621 test_expect_success 'submodule rebase -i' '
622 FAKE_LINES="1 squash 2 3" git rebase -i A
625 test_expect_success 'submodule conflict setup' '
626 git tag submodule-base &&
627 git checkout HEAD^ &&
629 cd sub && git checkout HEAD^ && echo 4 >elif &&
630 git add elif && git commit -m "submodule conflict"
631 ) &&
632 git add sub &&
633 test_tick &&
634 git commit -m "Conflict in submodule" &&
635 git tag submodule-topic
638 test_expect_success 'rebase -i continue with only submodule staged' '
639 test_must_fail git rebase -i submodule-base &&
640 git add sub &&
641 git rebase --continue &&
642 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
645 test_expect_success 'rebase -i continue with unstaged submodule' '
646 git checkout submodule-topic &&
647 git reset --hard &&
648 test_must_fail git rebase -i submodule-base &&
649 git reset &&
650 git rebase --continue &&
651 test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
654 test_expect_success 'avoid unnecessary reset' '
655 git checkout master &&
656 git reset --hard &&
657 test-chmtime =123456789 file3 &&
658 git update-index --refresh &&
659 HEAD=$(git rev-parse HEAD) &&
660 git rebase -i HEAD~4 &&
661 test $HEAD = $(git rev-parse HEAD) &&
662 MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
663 test 123456789 = $MTIME
666 test_expect_success 'reword' '
667 git checkout -b reword-branch master &&
668 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
669 git show HEAD | grep "E changed" &&
670 test $(git rev-parse master) != $(git rev-parse HEAD) &&
671 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
672 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
673 git show HEAD^ | grep "D changed" &&
674 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
675 git show HEAD~3 | grep "B changed" &&
676 FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
677 git show HEAD~2 | grep "C changed"
680 test_expect_success 'rebase -i can copy notes' '
681 git config notes.rewrite.rebase true &&
682 git config notes.rewriteRef "refs/notes/*" &&
683 test_commit n1 &&
684 test_commit n2 &&
685 test_commit n3 &&
686 git notes add -m"a note" n3 &&
687 git rebase -i --onto n1 n2 &&
688 test "a note" = "$(git notes show HEAD)"
691 cat >expect <<EOF
692 an earlier note
694 a note
697 test_expect_success 'rebase -i can copy notes over a fixup' '
698 git reset --hard n3 &&
699 git notes add -m"an earlier note" n2 &&
700 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
701 git notes show > output &&
702 test_cmp expect output
705 test_expect_success 'rebase while detaching HEAD' '
706 git symbolic-ref HEAD &&
707 grandparent=$(git rev-parse HEAD~2) &&
708 test_tick &&
709 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
710 test $grandparent = $(git rev-parse HEAD~2) &&
711 test_must_fail git symbolic-ref HEAD
714 test_tick # Ensure that the rebased commits get a different timestamp.
715 test_expect_success 'always cherry-pick with --no-ff' '
716 git checkout no-ff-branch &&
717 git tag original-no-ff-branch &&
718 git rebase -i --no-ff A &&
719 touch empty &&
720 for p in 0 1 2
722 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
723 git diff HEAD~$p original-no-ff-branch~$p > out &&
724 test_cmp empty out
725 done &&
726 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
727 git diff HEAD~3 original-no-ff-branch~3 > out &&
728 test_cmp empty out
731 test_expect_success 'set up commits with funny messages' '
732 git checkout -b funny A &&
733 echo >>file1 &&
734 test_tick &&
735 git commit -a -m "end with slash\\" &&
736 echo >>file1 &&
737 test_tick &&
738 git commit -a -m "something (\000) that looks like octal" &&
739 echo >>file1 &&
740 test_tick &&
741 git commit -a -m "something (\n) that looks like a newline" &&
742 echo >>file1 &&
743 test_tick &&
744 git commit -a -m "another commit"
747 test_expect_success 'rebase-i history with funny messages' '
748 git rev-list A..funny >expect &&
749 test_tick &&
750 FAKE_LINES="1 2 3 4" git rebase -i A &&
751 git rev-list A.. >actual &&
752 test_cmp expect actual
756 test_expect_success 'prepare for rebase -i --exec' '
757 git checkout master &&
758 git checkout -b execute &&
759 test_commit one_exec main.txt one_exec &&
760 test_commit two_exec main.txt two_exec &&
761 test_commit three_exec main.txt three_exec
765 test_expect_success 'running "git rebase -i --exec git show HEAD"' '
766 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
768 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
769 export FAKE_LINES &&
770 git rebase -i HEAD~2 >expect
771 ) &&
772 sed -e "1,9d" expect >expected &&
773 test_cmp expected actual
777 test_expect_success 'running "git rebase --exec git show HEAD -i"' '
778 git reset --hard execute &&
779 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
781 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
782 export FAKE_LINES &&
783 git rebase -i HEAD~2 >expect
784 ) &&
785 sed -e "1,9d" expect >expected &&
786 test_cmp expected actual
790 test_expect_success 'running "git rebase -ix git show HEAD"' '
791 git reset --hard execute &&
792 git rebase -ix "git show HEAD" HEAD~2 >actual &&
794 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
795 export FAKE_LINES &&
796 git rebase -i HEAD~2 >expect
797 ) &&
798 sed -e "1,9d" expect >expected &&
799 test_cmp expected actual
803 test_expect_success 'rebase -ix with several <CMD>' '
804 git reset --hard execute &&
805 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
807 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
808 export FAKE_LINES &&
809 git rebase -i HEAD~2 >expect
810 ) &&
811 sed -e "1,9d" expect >expected &&
812 test_cmp expected actual
816 test_expect_success 'rebase -ix with several instances of --exec' '
817 git reset --hard execute &&
818 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
820 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
821 exec_git_show_HEAD exec_pwd" &&
822 export FAKE_LINES &&
823 git rebase -i HEAD~2 >expect
824 ) &&
825 sed -e "1,11d" expect >expected &&
826 test_cmp expected actual
830 test_expect_success 'rebase -ix with --autosquash' '
831 git reset --hard execute &&
832 git checkout -b autosquash &&
833 echo second >second.txt &&
834 git add second.txt &&
835 git commit -m "fixup! two_exec" &&
836 echo bis >bis.txt &&
837 git add bis.txt &&
838 git commit -m "fixup! two_exec" &&
840 git checkout -b autosquash_actual &&
841 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
842 ) &&
843 git checkout autosquash &&
845 git checkout -b autosquash_expected &&
846 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
847 export FAKE_LINES &&
848 git rebase -i HEAD~4 >expect
849 ) &&
850 sed -e "1,13d" expect >expected &&
851 test_cmp expected actual
855 test_expect_success 'rebase --exec without -i shows error message' '
856 git reset --hard execute &&
857 test_must_fail git rebase --exec "git show HEAD" HEAD~2 2>actual &&
858 echo "The --exec option must be used with the --interactive option" >expected &&
859 test_i18ncmp expected actual
863 test_expect_success 'rebase -i --exec without <CMD>' '
864 git reset --hard execute &&
865 test_must_fail git rebase -i --exec 2>tmp &&
866 sed -e "1d" tmp >actual &&
867 test_must_fail git rebase -h >expected &&
868 test_cmp expected actual &&
869 git checkout master
872 test_expect_success 'rebase -i --root re-order and drop commits' '
873 git checkout E &&
874 FAKE_LINES="3 1 2 5" git rebase -i --root &&
875 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
876 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
877 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
878 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
879 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
882 test_expect_success 'rebase -i --root retain root commit author and message' '
883 git checkout A &&
884 echo B >file7 &&
885 git add file7 &&
886 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
887 FAKE_LINES="2" git rebase -i --root &&
888 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
889 git cat-file commit HEAD | grep -q "^different author$"
892 test_expect_success 'rebase -i --root temporary sentinel commit' '
893 git checkout B &&
895 FAKE_LINES="2" &&
896 export FAKE_LINES &&
897 test_must_fail git rebase -i --root
898 ) &&
899 git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
900 git rebase --abort
903 test_expect_success 'rebase -i --root fixup root commit' '
904 git checkout B &&
905 FAKE_LINES="1 fixup 2" git rebase -i --root &&
906 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
907 test B = $(git show HEAD:file1) &&
908 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
911 test_expect_success 'rebase --edit-todo does not works on non-interactive rebase' '
912 git reset --hard &&
913 git checkout conflict-branch &&
914 test_must_fail git rebase --onto HEAD~2 HEAD~ &&
915 test_must_fail git rebase --edit-todo &&
916 git rebase --abort
919 test_expect_success 'rebase --edit-todo can be used to modify todo' '
920 git reset --hard &&
921 git checkout no-conflict-branch^0 &&
922 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
923 FAKE_LINES="2 1" git rebase --edit-todo &&
924 git rebase --continue
925 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
926 test L = $(git cat-file commit HEAD | sed -ne \$p)
929 test_expect_success 'rebase -i produces readable reflog' '
930 git reset --hard &&
931 git branch -f branch-reflog-test H &&
932 git rebase -i --onto I F branch-reflog-test &&
933 cat >expect <<-\EOF &&
934 rebase -i (start): checkout I
935 rebase -i (pick): G
936 rebase -i (pick): H
937 rebase -i (finish): returning to refs/heads/branch-reflog-test
939 tail -n 4 .git/logs/HEAD |
940 sed -e "s/.* //" >actual &&
941 test_cmp expect actual
944 test_expect_success 'rebase -i respects core.commentchar' '
945 git reset --hard &&
946 git checkout E^0 &&
947 test_config core.commentchar "\\" &&
948 write_script remove-all-but-first.sh <<-\EOF &&
949 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
950 mv "$1.tmp" "$1"
952 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
953 git rebase -i B &&
954 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
957 test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
958 test_when_finished "git branch -D torebase" &&
959 git checkout -b torebase branch1 &&
960 upstream=$(git rev-parse ":/J") &&
961 onto=$(git rev-parse ":/A") &&
962 git rebase --onto $onto $upstream &&
963 git reset --hard branch1 &&
964 git rebase --onto ":/A" ":/J" &&
965 git checkout branch1
968 test_expect_success 'rebase -i with --strategy and -X' '
969 git checkout -b conflict-merge-use-theirs conflict-branch &&
970 git reset --hard HEAD^ &&
971 echo five >conflict &&
972 echo Z >file1 &&
973 git commit -a -m "one file conflict" &&
974 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
975 test $(git show conflict-branch:conflict) = $(cat conflict) &&
976 test $(cat file1) = Z
979 test_done