Merge branch 'jk/fetch-all-peeled-fix'
[git.git] / t / t3404-rebase-interactive.sh
blobc5d39e2b23f0f257af1553a9f50efc3f6cf0ad5e
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 # WARNING: Modifications to the initial repository can change the SHA ID used
33 # in the expect2 file for the 'stop on conflicting pick' test.
35 test_expect_success 'setup' '
36 test_commit A file1 &&
37 test_commit B file1 &&
38 test_commit C file2 &&
39 test_commit D file1 &&
40 test_commit E file3 &&
41 git checkout -b branch1 A &&
42 test_commit F file4 &&
43 test_commit G file1 &&
44 test_commit H file5 &&
45 git checkout -b branch2 F &&
46 test_commit I file6 &&
47 git checkout -b conflict-branch A &&
48 test_commit one conflict &&
49 test_commit two conflict &&
50 test_commit three conflict &&
51 test_commit four conflict &&
52 git checkout -b no-conflict-branch A &&
53 test_commit J fileJ &&
54 test_commit K fileK &&
55 test_commit L fileL &&
56 test_commit M fileM &&
57 git checkout -b no-ff-branch A &&
58 test_commit N fileN &&
59 test_commit O fileO &&
60 test_commit P fileP
63 # "exec" commands are run with the user shell by default, but this may
64 # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work
65 # to create a file. Unsetting SHELL avoids such non-portable behavior
66 # in tests. It must be exported for it to take effect where needed.
67 SHELL=
68 export SHELL
70 test_expect_success 'rebase --keep-empty' '
71 git checkout -b emptybranch master &&
72 git commit --allow-empty -m "empty" &&
73 git rebase --keep-empty -i HEAD~2 &&
74 git log --oneline >actual &&
75 test_line_count = 6 actual
78 test_expect_success 'rebase -i with the exec command' '
79 git checkout master &&
81 set_fake_editor &&
82 FAKE_LINES="1 exec_>touch-one
83 2 exec_>touch-two exec_false exec_>touch-three
84 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
85 export FAKE_LINES &&
86 test_must_fail git rebase -i A
87 ) &&
88 test_path_is_file touch-one &&
89 test_path_is_file touch-two &&
90 test_path_is_missing touch-three " (should have stopped before)" &&
91 test_cmp_rev C HEAD &&
92 git rebase --continue &&
93 test_path_is_file touch-three &&
94 test_path_is_file "touch-file name with spaces" &&
95 test_path_is_file touch-after-semicolon &&
96 test_cmp_rev master HEAD &&
97 rm -f touch-*
100 test_expect_success 'rebase -i with the exec command runs from tree root' '
101 git checkout master &&
102 mkdir subdir && (cd subdir &&
103 set_fake_editor &&
104 FAKE_LINES="1 exec_>touch-subdir" \
105 git rebase -i HEAD^
106 ) &&
107 test_path_is_file touch-subdir &&
108 rm -fr subdir
111 test_expect_success 'rebase -i with exec allows git commands in subdirs' '
112 test_when_finished "rm -rf subdir" &&
113 test_when_finished "git rebase --abort ||:" &&
114 git checkout master &&
115 mkdir subdir && (cd subdir &&
116 set_fake_editor &&
117 FAKE_LINES="1 exec_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \
118 git rebase -i HEAD^
122 test_expect_success 'rebase -i with the exec command checks tree cleanness' '
123 git checkout master &&
124 set_fake_editor &&
125 test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^ &&
126 test_cmp_rev master^ HEAD &&
127 git reset --hard &&
128 git rebase --continue
131 test_expect_success 'rebase -i with exec of inexistent command' '
132 git checkout master &&
133 test_when_finished "git rebase --abort" &&
134 set_fake_editor &&
135 test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
136 git rebase -i HEAD^ >actual 2>&1 &&
137 ! grep "Maybe git-rebase is broken" actual
140 test_expect_success 'no changes are a nop' '
141 git checkout branch2 &&
142 set_fake_editor &&
143 git rebase -i F &&
144 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
145 test $(git rev-parse I) = $(git rev-parse HEAD)
148 test_expect_success 'test the [branch] option' '
149 git checkout -b dead-end &&
150 git rm file6 &&
151 git commit -m "stop here" &&
152 set_fake_editor &&
153 git rebase -i F branch2 &&
154 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
155 test $(git rev-parse I) = $(git rev-parse branch2) &&
156 test $(git rev-parse I) = $(git rev-parse HEAD)
159 test_expect_success 'test --onto <branch>' '
160 git checkout -b test-onto branch2 &&
161 set_fake_editor &&
162 git rebase -i --onto branch1 F &&
163 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
164 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
165 test $(git rev-parse I) = $(git rev-parse branch2)
168 test_expect_success 'rebase on top of a non-conflicting commit' '
169 git checkout branch1 &&
170 git tag original-branch1 &&
171 set_fake_editor &&
172 git rebase -i branch2 &&
173 test file6 = $(git diff --name-only original-branch1) &&
174 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
175 test $(git rev-parse I) = $(git rev-parse branch2) &&
176 test $(git rev-parse I) = $(git rev-parse HEAD~2)
179 test_expect_success 'reflog for the branch shows state before rebase' '
180 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
183 test_expect_success 'reflog for the branch shows correct finish message' '
184 printf "rebase -i (finish): refs/heads/branch1 onto %s\n" \
185 "$(git rev-parse branch2)" >expected &&
186 git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
187 test_cmp expected actual
190 test_expect_success 'exchange two commits' '
191 set_fake_editor &&
192 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
193 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
194 test G = $(git cat-file commit HEAD | sed -ne \$p)
197 cat > expect << EOF
198 diff --git a/file1 b/file1
199 index f70f10e..fd79235 100644
200 --- a/file1
201 +++ b/file1
202 @@ -1 +1 @@
207 cat > expect2 << EOF
208 <<<<<<< HEAD
210 =======
212 >>>>>>> 5d18e54... G
215 test_expect_success 'stop on conflicting pick' '
216 git tag new-branch1 &&
217 set_fake_editor &&
218 test_must_fail git rebase -i master &&
219 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
220 test_cmp expect .git/rebase-merge/patch &&
221 test_cmp expect2 file1 &&
222 test "$(git diff --name-status |
223 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
224 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
225 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
228 test_expect_success 'show conflicted patch' '
229 GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
230 grep "show.*REBASE_HEAD" stderr &&
231 # the original stopped-sha1 is abbreviated
232 stopped_sha1="$(git rev-parse $(cat ".git/rebase-merge/stopped-sha"))" &&
233 test "$(git rev-parse REBASE_HEAD)" = "$stopped_sha1"
236 test_expect_success 'abort' '
237 git rebase --abort &&
238 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
239 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
240 test_path_is_missing .git/rebase-merge
243 test_expect_success 'abort with error when new base cannot be checked out' '
244 git rm --cached file1 &&
245 git commit -m "remove file in base" &&
246 set_fake_editor &&
247 test_must_fail git rebase -i master > output 2>&1 &&
248 test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
249 output &&
250 test_i18ngrep "file1" output &&
251 test_path_is_missing .git/rebase-merge &&
252 git reset --hard HEAD^
255 test_expect_success 'retain authorship' '
256 echo A > file7 &&
257 git add file7 &&
258 test_tick &&
259 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
260 git tag twerp &&
261 set_fake_editor &&
262 git rebase -i --onto master HEAD^ &&
263 git show HEAD | grep "^Author: Twerp Snog"
266 test_expect_success 'retain authorship w/ conflicts' '
267 git reset --hard twerp &&
268 test_commit a conflict a conflict-a &&
269 git reset --hard twerp &&
270 GIT_AUTHOR_NAME=AttributeMe \
271 test_commit b conflict b conflict-b &&
272 set_fake_editor &&
273 test_must_fail git rebase -i conflict-a &&
274 echo resolved >conflict &&
275 git add conflict &&
276 git rebase --continue &&
277 test $(git rev-parse conflict-a^0) = $(git rev-parse HEAD^) &&
278 git show >out &&
279 grep AttributeMe out
282 test_expect_success 'squash' '
283 git reset --hard twerp &&
284 echo B > file7 &&
285 test_tick &&
286 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
287 echo "******************************" &&
288 set_fake_editor &&
289 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
290 git rebase -i --onto master HEAD~2 &&
291 test B = $(cat file7) &&
292 test $(git rev-parse HEAD^) = $(git rev-parse master)
295 test_expect_success 'retain authorship when squashing' '
296 git show HEAD | grep "^Author: Twerp Snog"
299 test_expect_success '-p handles "no changes" gracefully' '
300 HEAD=$(git rev-parse HEAD) &&
301 set_fake_editor &&
302 git rebase -i -p HEAD^ &&
303 git update-index --refresh &&
304 git diff-files --quiet &&
305 git diff-index --quiet --cached HEAD -- &&
306 test $HEAD = $(git rev-parse HEAD)
309 test_expect_failure 'exchange two commits with -p' '
310 git checkout H &&
311 set_fake_editor &&
312 FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
313 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
314 test G = $(git cat-file commit HEAD | sed -ne \$p)
317 test_expect_success 'preserve merges with -p' '
318 git checkout -b to-be-preserved master^ &&
319 : > unrelated-file &&
320 git add unrelated-file &&
321 test_tick &&
322 git commit -m "unrelated" &&
323 git checkout -b another-branch master &&
324 echo B > file1 &&
325 test_tick &&
326 git commit -m J file1 &&
327 test_tick &&
328 git merge to-be-preserved &&
329 echo C > file1 &&
330 test_tick &&
331 git commit -m K file1 &&
332 echo D > file1 &&
333 test_tick &&
334 git commit -m L1 file1 &&
335 git checkout HEAD^ &&
336 echo 1 > unrelated-file &&
337 test_tick &&
338 git commit -m L2 unrelated-file &&
339 test_tick &&
340 git merge another-branch &&
341 echo E > file1 &&
342 test_tick &&
343 git commit -m M file1 &&
344 git checkout -b to-be-rebased &&
345 test_tick &&
346 set_fake_editor &&
347 git rebase -i -p --onto branch1 master &&
348 git update-index --refresh &&
349 git diff-files --quiet &&
350 git diff-index --quiet --cached HEAD -- &&
351 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
352 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
353 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
354 test $(git show HEAD~5:file1) = B &&
355 test $(git show HEAD~3:file1) = C &&
356 test $(git show HEAD:file1) = E &&
357 test $(git show HEAD:unrelated-file) = 1
360 test_expect_success 'edit ancestor with -p' '
361 set_fake_editor &&
362 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
363 echo 2 > unrelated-file &&
364 test_tick &&
365 git commit -m L2-modified --amend unrelated-file &&
366 git rebase --continue &&
367 git update-index --refresh &&
368 git diff-files --quiet &&
369 git diff-index --quiet --cached HEAD -- &&
370 test $(git show HEAD:unrelated-file) = 2
373 test_expect_success '--continue tries to commit' '
374 test_tick &&
375 set_fake_editor &&
376 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
377 echo resolved > file1 &&
378 git add file1 &&
379 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
380 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
381 git show HEAD | grep chouette
384 test_expect_success 'verbose flag is heeded, even after --continue' '
385 git reset --hard master@{1} &&
386 test_tick &&
387 set_fake_editor &&
388 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
389 echo resolved > file1 &&
390 git add file1 &&
391 git rebase --continue > output &&
392 grep "^ file1 | 2 +-$" output
395 test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' '
396 base=$(git rev-parse HEAD~4) &&
397 set_fake_editor &&
398 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
399 EXPECT_HEADER_COUNT=4 \
400 git rebase -i $base &&
401 test $base = $(git rev-parse HEAD^) &&
402 test 1 = $(git show | grep ONCE | wc -l)
405 test_expect_success C_LOCALE_OUTPUT 'multi-fixup does not fire up editor' '
406 git checkout -b multi-fixup E &&
407 base=$(git rev-parse HEAD~4) &&
408 set_fake_editor &&
409 FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
410 git rebase -i $base &&
411 test $base = $(git rev-parse HEAD^) &&
412 test 0 = $(git show | grep NEVER | wc -l) &&
413 git checkout to-be-rebased &&
414 git branch -D multi-fixup
417 test_expect_success 'commit message used after conflict' '
418 git checkout -b conflict-fixup conflict-branch &&
419 base=$(git rev-parse HEAD~4) &&
420 set_fake_editor &&
421 test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base &&
422 echo three > conflict &&
423 git add conflict &&
424 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
425 git rebase --continue &&
426 test $base = $(git rev-parse HEAD^) &&
427 test 1 = $(git show | grep ONCE | wc -l) &&
428 git checkout to-be-rebased &&
429 git branch -D conflict-fixup
432 test_expect_success 'commit message retained after conflict' '
433 git checkout -b conflict-squash conflict-branch &&
434 base=$(git rev-parse HEAD~4) &&
435 set_fake_editor &&
436 test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base &&
437 echo three > conflict &&
438 git add conflict &&
439 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
440 git rebase --continue &&
441 test $base = $(git rev-parse HEAD^) &&
442 test 2 = $(git show | grep TWICE | wc -l) &&
443 git checkout to-be-rebased &&
444 git branch -D conflict-squash
447 cat > expect-squash-fixup << EOF
452 ONCE
455 test_expect_success C_LOCALE_OUTPUT 'squash and fixup generate correct log messages' '
456 git checkout -b squash-fixup E &&
457 base=$(git rev-parse HEAD~4) &&
458 set_fake_editor &&
459 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
460 EXPECT_HEADER_COUNT=4 \
461 git rebase -i $base &&
462 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
463 test_cmp expect-squash-fixup actual-squash-fixup &&
464 git cat-file commit HEAD@{2} |
465 grep "^# This is a combination of 3 commits\." &&
466 git cat-file commit HEAD@{3} |
467 grep "^# This is a combination of 2 commits\." &&
468 git checkout to-be-rebased &&
469 git branch -D squash-fixup
472 test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' '
473 git checkout -b skip-comments E &&
474 base=$(git rev-parse HEAD~4) &&
475 set_fake_editor &&
476 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
477 EXPECT_HEADER_COUNT=4 \
478 git rebase -i $base &&
479 test $base = $(git rev-parse HEAD^) &&
480 test 1 = $(git show | grep ONCE | wc -l) &&
481 git checkout to-be-rebased &&
482 git branch -D skip-comments
485 test_expect_success C_LOCALE_OUTPUT 'squash ignores blank lines' '
486 git checkout -b skip-blank-lines E &&
487 base=$(git rev-parse HEAD~4) &&
488 set_fake_editor &&
489 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
490 EXPECT_HEADER_COUNT=4 \
491 git rebase -i $base &&
492 test $base = $(git rev-parse HEAD^) &&
493 test 1 = $(git show | grep ONCE | wc -l) &&
494 git checkout to-be-rebased &&
495 git branch -D skip-blank-lines
498 test_expect_success 'squash works as expected' '
499 git checkout -b squash-works no-conflict-branch &&
500 one=$(git rev-parse HEAD~3) &&
501 set_fake_editor &&
502 FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
503 git rebase -i HEAD~3 &&
504 test $one = $(git rev-parse HEAD~2)
507 test_expect_success 'interrupted squash works as expected' '
508 git checkout -b interrupted-squash conflict-branch &&
509 one=$(git rev-parse HEAD~3) &&
510 set_fake_editor &&
511 test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
512 (echo one; echo two; echo four) > conflict &&
513 git add conflict &&
514 test_must_fail git rebase --continue &&
515 echo resolved > conflict &&
516 git add conflict &&
517 git rebase --continue &&
518 test $one = $(git rev-parse HEAD~2)
521 test_expect_success 'interrupted squash works as expected (case 2)' '
522 git checkout -b interrupted-squash2 conflict-branch &&
523 one=$(git rev-parse HEAD~3) &&
524 set_fake_editor &&
525 test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
526 (echo one; echo four) > conflict &&
527 git add conflict &&
528 test_must_fail git rebase --continue &&
529 (echo one; echo two; echo four) > conflict &&
530 git add conflict &&
531 test_must_fail git rebase --continue &&
532 echo resolved > conflict &&
533 git add conflict &&
534 git rebase --continue &&
535 test $one = $(git rev-parse HEAD~2)
538 test_expect_success '--continue tries to commit, even for "edit"' '
539 echo unrelated > file7 &&
540 git add file7 &&
541 test_tick &&
542 git commit -m "unrelated change" &&
543 parent=$(git rev-parse HEAD^) &&
544 test_tick &&
545 set_fake_editor &&
546 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
547 echo edited > file7 &&
548 git add file7 &&
549 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
550 test edited = $(git show HEAD:file7) &&
551 git show HEAD | grep chouette &&
552 test $parent = $(git rev-parse HEAD^)
555 test_expect_success 'aborted --continue does not squash commits after "edit"' '
556 test_when_finished "git rebase --abort" &&
557 old=$(git rev-parse HEAD) &&
558 test_tick &&
559 set_fake_editor &&
560 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
561 echo "edited again" > file7 &&
562 git add file7 &&
563 echo all the things >>conflict &&
564 test_must_fail git rebase --continue &&
565 test $old = $(git rev-parse HEAD)
568 test_expect_success 'auto-amend only edited commits after "edit"' '
569 test_tick &&
570 set_fake_editor &&
571 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
572 echo "edited again" > file7 &&
573 git add file7 &&
574 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
575 echo "and again" > file7 &&
576 git add file7 &&
577 test_tick &&
578 test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue &&
579 git rebase --abort
582 test_expect_success 'clean error after failed "exec"' '
583 test_tick &&
584 test_when_finished "git rebase --abort || :" &&
585 set_fake_editor &&
586 test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ &&
587 echo "edited again" > file7 &&
588 git add file7 &&
589 test_must_fail git rebase --continue 2>error &&
590 test_i18ngrep "you have staged changes in your working tree" error
593 test_expect_success 'rebase a detached HEAD' '
594 grandparent=$(git rev-parse HEAD~2) &&
595 git checkout $(git rev-parse HEAD) &&
596 test_tick &&
597 set_fake_editor &&
598 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
599 test $grandparent = $(git rev-parse HEAD~2)
602 test_expect_success 'rebase a commit violating pre-commit' '
604 mkdir -p .git/hooks &&
605 write_script .git/hooks/pre-commit <<-\EOF &&
606 test -z "$(git diff --cached --check)"
608 echo "monde! " >> file1 &&
609 test_tick &&
610 test_must_fail git commit -m doesnt-verify file1 &&
611 git commit -m doesnt-verify --no-verify file1 &&
612 test_tick &&
613 set_fake_editor &&
614 FAKE_LINES=2 git rebase -i HEAD~2
618 test_expect_success 'rebase with a file named HEAD in worktree' '
620 rm -fr .git/hooks &&
621 git reset --hard &&
622 git checkout -b branch3 A &&
625 GIT_AUTHOR_NAME="Squashed Away" &&
626 export GIT_AUTHOR_NAME &&
627 >HEAD &&
628 git add HEAD &&
629 git commit -m "Add head" &&
630 >BODY &&
631 git add BODY &&
632 git commit -m "Add body"
633 ) &&
635 set_fake_editor &&
636 FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
637 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
641 test_expect_success 'do "noop" when there is nothing to cherry-pick' '
643 git checkout -b branch4 HEAD &&
644 GIT_EDITOR=: git commit --amend \
645 --author="Somebody else <somebody@else.com>" &&
646 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
647 set_fake_editor &&
648 git rebase -i branch3 &&
649 test $(git rev-parse branch3) = $(git rev-parse branch4)
653 test_expect_success 'submodule rebase setup' '
654 git checkout A &&
655 mkdir sub &&
657 cd sub && git init && >elif &&
658 git add elif && git commit -m "submodule initial"
659 ) &&
660 echo 1 >file1 &&
661 git add file1 sub &&
662 test_tick &&
663 git commit -m "One" &&
664 echo 2 >file1 &&
665 test_tick &&
666 git commit -a -m "Two" &&
668 cd sub && echo 3 >elif &&
669 git commit -a -m "submodule second"
670 ) &&
671 test_tick &&
672 set_fake_editor &&
673 git commit -a -m "Three changes submodule"
676 test_expect_success 'submodule rebase -i' '
677 set_fake_editor &&
678 FAKE_LINES="1 squash 2 3" git rebase -i A
681 test_expect_success 'submodule conflict setup' '
682 git tag submodule-base &&
683 git checkout HEAD^ &&
685 cd sub && git checkout HEAD^ && echo 4 >elif &&
686 git add elif && git commit -m "submodule conflict"
687 ) &&
688 git add sub &&
689 test_tick &&
690 git commit -m "Conflict in submodule" &&
691 git tag submodule-topic
694 test_expect_success 'rebase -i continue with only submodule staged' '
695 set_fake_editor &&
696 test_must_fail git rebase -i submodule-base &&
697 git add sub &&
698 git rebase --continue &&
699 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
702 test_expect_success 'rebase -i continue with unstaged submodule' '
703 git checkout submodule-topic &&
704 git reset --hard &&
705 set_fake_editor &&
706 test_must_fail git rebase -i submodule-base &&
707 git reset &&
708 git rebase --continue &&
709 test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
712 test_expect_success 'avoid unnecessary reset' '
713 git checkout master &&
714 git reset --hard &&
715 test-tool chmtime =123456789 file3 &&
716 git update-index --refresh &&
717 HEAD=$(git rev-parse HEAD) &&
718 set_fake_editor &&
719 git rebase -i HEAD~4 &&
720 test $HEAD = $(git rev-parse HEAD) &&
721 MTIME=$(test-tool chmtime --get file3) &&
722 test 123456789 = $MTIME
725 test_expect_success 'reword' '
726 git checkout -b reword-branch master &&
727 set_fake_editor &&
728 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
729 git show HEAD | grep "E changed" &&
730 test $(git rev-parse master) != $(git rev-parse HEAD) &&
731 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
732 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
733 git show HEAD^ | grep "D changed" &&
734 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
735 git show HEAD~3 | grep "B changed" &&
736 FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
737 git show HEAD~2 | grep "C changed"
740 test_expect_success 'rebase -i can copy notes' '
741 git config notes.rewrite.rebase true &&
742 git config notes.rewriteRef "refs/notes/*" &&
743 test_commit n1 &&
744 test_commit n2 &&
745 test_commit n3 &&
746 git notes add -m"a note" n3 &&
747 set_fake_editor &&
748 git rebase -i --onto n1 n2 &&
749 test "a note" = "$(git notes show HEAD)"
752 cat >expect <<EOF
753 an earlier note
755 a note
758 test_expect_success 'rebase -i can copy notes over a fixup' '
759 git reset --hard n3 &&
760 git notes add -m"an earlier note" n2 &&
761 set_fake_editor &&
762 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
763 git notes show > output &&
764 test_cmp expect output
767 test_expect_success 'rebase while detaching HEAD' '
768 git symbolic-ref HEAD &&
769 grandparent=$(git rev-parse HEAD~2) &&
770 test_tick &&
771 set_fake_editor &&
772 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
773 test $grandparent = $(git rev-parse HEAD~2) &&
774 test_must_fail git symbolic-ref HEAD
777 test_tick # Ensure that the rebased commits get a different timestamp.
778 test_expect_success 'always cherry-pick with --no-ff' '
779 git checkout no-ff-branch &&
780 git tag original-no-ff-branch &&
781 set_fake_editor &&
782 git rebase -i --no-ff A &&
783 touch empty &&
784 for p in 0 1 2
786 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
787 git diff HEAD~$p original-no-ff-branch~$p > out &&
788 test_cmp empty out
789 done &&
790 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
791 git diff HEAD~3 original-no-ff-branch~3 > out &&
792 test_cmp empty out
795 test_expect_success 'set up commits with funny messages' '
796 git checkout -b funny A &&
797 echo >>file1 &&
798 test_tick &&
799 git commit -a -m "end with slash\\" &&
800 echo >>file1 &&
801 test_tick &&
802 git commit -a -m "something (\000) that looks like octal" &&
803 echo >>file1 &&
804 test_tick &&
805 git commit -a -m "something (\n) that looks like a newline" &&
806 echo >>file1 &&
807 test_tick &&
808 git commit -a -m "another commit"
811 test_expect_success 'rebase-i history with funny messages' '
812 git rev-list A..funny >expect &&
813 test_tick &&
814 set_fake_editor &&
815 FAKE_LINES="1 2 3 4" git rebase -i A &&
816 git rev-list A.. >actual &&
817 test_cmp expect actual
820 test_expect_success 'prepare for rebase -i --exec' '
821 git checkout master &&
822 git checkout -b execute &&
823 test_commit one_exec main.txt one_exec &&
824 test_commit two_exec main.txt two_exec &&
825 test_commit three_exec main.txt three_exec
828 test_expect_success 'running "git rebase -i --exec git show HEAD"' '
829 set_fake_editor &&
830 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
832 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
833 export FAKE_LINES &&
834 git rebase -i HEAD~2 >expect
835 ) &&
836 sed -e "1,9d" expect >expected &&
837 test_cmp expected actual
840 test_expect_success 'running "git rebase --exec git show HEAD -i"' '
841 git reset --hard execute &&
842 set_fake_editor &&
843 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
845 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
846 export FAKE_LINES &&
847 git rebase -i HEAD~2 >expect
848 ) &&
849 sed -e "1,9d" expect >expected &&
850 test_cmp expected actual
853 test_expect_success 'running "git rebase -ix git show HEAD"' '
854 git reset --hard execute &&
855 set_fake_editor &&
856 git rebase -ix "git show HEAD" HEAD~2 >actual &&
858 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
859 export FAKE_LINES &&
860 git rebase -i HEAD~2 >expect
861 ) &&
862 sed -e "1,9d" expect >expected &&
863 test_cmp expected actual
867 test_expect_success 'rebase -ix with several <CMD>' '
868 git reset --hard execute &&
869 set_fake_editor &&
870 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
872 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
873 export FAKE_LINES &&
874 git rebase -i HEAD~2 >expect
875 ) &&
876 sed -e "1,9d" expect >expected &&
877 test_cmp expected actual
880 test_expect_success 'rebase -ix with several instances of --exec' '
881 git reset --hard execute &&
882 set_fake_editor &&
883 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
885 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
886 exec_git_show_HEAD exec_pwd" &&
887 export FAKE_LINES &&
888 git rebase -i HEAD~2 >expect
889 ) &&
890 sed -e "1,11d" expect >expected &&
891 test_cmp expected actual
894 test_expect_success C_LOCALE_OUTPUT 'rebase -ix with --autosquash' '
895 git reset --hard execute &&
896 git checkout -b autosquash &&
897 echo second >second.txt &&
898 git add second.txt &&
899 git commit -m "fixup! two_exec" &&
900 echo bis >bis.txt &&
901 git add bis.txt &&
902 git commit -m "fixup! two_exec" &&
903 set_fake_editor &&
905 git checkout -b autosquash_actual &&
906 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
907 ) &&
908 git checkout autosquash &&
910 git checkout -b autosquash_expected &&
911 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
912 export FAKE_LINES &&
913 git rebase -i HEAD~4 >expect
914 ) &&
915 sed -e "1,13d" expect >expected &&
916 test_cmp expected actual
919 test_expect_success 'rebase --exec works without -i ' '
920 git reset --hard execute &&
921 rm -rf exec_output &&
922 EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual &&
923 test_i18ngrep "Successfully rebased and updated" actual &&
924 test_line_count = 2 exec_output &&
925 test_path_is_missing invoked_editor
928 test_expect_success 'rebase -i --exec without <CMD>' '
929 git reset --hard execute &&
930 set_fake_editor &&
931 test_must_fail git rebase -i --exec 2>actual &&
932 test_i18ngrep "requires a value" actual &&
933 git checkout master
936 test_expect_success 'rebase -i --root re-order and drop commits' '
937 git checkout E &&
938 set_fake_editor &&
939 FAKE_LINES="3 1 2 5" git rebase -i --root &&
940 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
941 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
942 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
943 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
944 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
947 test_expect_success 'rebase -i --root retain root commit author and message' '
948 git checkout A &&
949 echo B >file7 &&
950 git add file7 &&
951 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
952 set_fake_editor &&
953 FAKE_LINES="2" git rebase -i --root &&
954 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
955 git cat-file commit HEAD | grep -q "^different author$"
958 test_expect_success 'rebase -i --root temporary sentinel commit' '
959 git checkout B &&
960 set_fake_editor &&
961 test_must_fail env FAKE_LINES="2" git rebase -i --root &&
962 git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
963 git rebase --abort
966 test_expect_success 'rebase -i --root fixup root commit' '
967 git checkout B &&
968 set_fake_editor &&
969 FAKE_LINES="1 fixup 2" git rebase -i --root &&
970 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
971 test B = $(git show HEAD:file1) &&
972 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
975 test_expect_success 'rebase -i --root reword root commit' '
976 test_when_finished "test_might_fail git rebase --abort" &&
977 git checkout -b reword-root-branch master &&
978 set_fake_editor &&
979 FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \
980 git rebase -i --root &&
981 git show HEAD^ | grep "A changed" &&
982 test -z "$(git show -s --format=%p HEAD^)"
985 test_expect_success 'rebase -i --root when root has untracked file confilct' '
986 test_when_finished "reset_rebase" &&
987 git checkout -b failing-root-pick A &&
988 echo x >file2 &&
989 git rm file1 &&
990 git commit -m "remove file 1 add file 2" &&
991 echo z >file1 &&
992 set_fake_editor &&
993 test_must_fail env FAKE_LINES="1 2" git rebase -i --root &&
994 rm file1 &&
995 git rebase --continue &&
996 test "$(git log -1 --format=%B)" = "remove file 1 add file 2" &&
997 test "$(git rev-list --count HEAD)" = 2
1000 test_expect_success 'rebase -i --root reword root when root has untracked file conflict' '
1001 test_when_finished "reset_rebase" &&
1002 echo z>file1 &&
1003 set_fake_editor &&
1004 test_must_fail env FAKE_LINES="reword 1 2" \
1005 FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root &&
1006 rm file1 &&
1007 FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue &&
1008 test "$(git log -1 --format=%B HEAD^)" = "Reworded A" &&
1009 test "$(git rev-list --count HEAD)" = 2
1012 test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' '
1013 git checkout reword-root-branch &&
1014 git reset --hard &&
1015 git checkout conflict-branch &&
1016 set_fake_editor &&
1017 test_must_fail git rebase --onto HEAD~2 HEAD~ &&
1018 test_must_fail git rebase --edit-todo &&
1019 git rebase --abort
1022 test_expect_success 'rebase --edit-todo can be used to modify todo' '
1023 git reset --hard &&
1024 git checkout no-conflict-branch^0 &&
1025 set_fake_editor &&
1026 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
1027 FAKE_LINES="2 1" git rebase --edit-todo &&
1028 git rebase --continue &&
1029 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1030 test L = $(git cat-file commit HEAD | sed -ne \$p)
1033 test_expect_success 'rebase -i produces readable reflog' '
1034 git reset --hard &&
1035 git branch -f branch-reflog-test H &&
1036 set_fake_editor &&
1037 git rebase -i --onto I F branch-reflog-test &&
1038 cat >expect <<-\EOF &&
1039 rebase -i (finish): returning to refs/heads/branch-reflog-test
1040 rebase -i (pick): H
1041 rebase -i (pick): G
1042 rebase -i (start): checkout I
1044 git reflog -n4 HEAD |
1045 sed "s/[^:]*: //" >actual &&
1046 test_cmp expect actual
1049 test_expect_success 'rebase -i respects core.commentchar' '
1050 git reset --hard &&
1051 git checkout E^0 &&
1052 test_config core.commentchar "\\" &&
1053 write_script remove-all-but-first.sh <<-\EOF &&
1054 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
1055 mv "$1.tmp" "$1"
1057 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1058 git rebase -i B &&
1059 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1062 test_expect_success 'rebase -i respects core.commentchar=auto' '
1063 test_config core.commentchar auto &&
1064 write_script copy-edit-script.sh <<-\EOF &&
1065 cp "$1" edit-script
1067 test_set_editor "$(pwd)/copy-edit-script.sh" &&
1068 test_when_finished "git rebase --abort || :" &&
1069 git rebase -i HEAD^ &&
1070 test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1073 test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1074 test_when_finished "git branch -D torebase" &&
1075 git checkout -b torebase branch1 &&
1076 upstream=$(git rev-parse ":/J") &&
1077 onto=$(git rev-parse ":/A") &&
1078 git rebase --onto $onto $upstream &&
1079 git reset --hard branch1 &&
1080 git rebase --onto ":/A" ":/J" &&
1081 git checkout branch1
1084 test_expect_success 'rebase -i with --strategy and -X' '
1085 git checkout -b conflict-merge-use-theirs conflict-branch &&
1086 git reset --hard HEAD^ &&
1087 echo five >conflict &&
1088 echo Z >file1 &&
1089 git commit -a -m "one file conflict" &&
1090 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1091 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1092 test $(cat file1) = Z
1095 test_expect_success 'interrupted rebase -i with --strategy and -X' '
1096 git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1097 git reset --hard HEAD^ &&
1098 >breakpoint &&
1099 git add breakpoint &&
1100 git commit -m "breakpoint for interactive mode" &&
1101 echo five >conflict &&
1102 echo Z >file1 &&
1103 git commit -a -m "one file conflict" &&
1104 set_fake_editor &&
1105 FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive -Xours conflict-branch &&
1106 git rebase --continue &&
1107 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1108 test $(cat file1) = Z
1111 test_expect_success 'rebase -i error on commits with \ in message' '
1112 current_head=$(git rev-parse HEAD) &&
1113 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1114 test_commit TO-REMOVE will-conflict old-content &&
1115 test_commit "\temp" will-conflict new-content dummy &&
1116 test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1117 test_expect_code 1 grep " emp" error
1120 test_expect_success 'short SHA-1 setup' '
1121 test_when_finished "git checkout master" &&
1122 git checkout --orphan collide &&
1123 git rm -rf . &&
1125 unset test_tick &&
1126 test_commit collide1 collide &&
1127 test_commit --notick collide2 collide &&
1128 test_commit --notick collide3 collide
1132 test_expect_success 'short SHA-1 collide' '
1133 test_when_finished "reset_rebase && git checkout master" &&
1134 git checkout collide &&
1136 unset test_tick &&
1137 test_tick &&
1138 set_fake_editor &&
1139 FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1140 FAKE_LINES="reword 1 2" git rebase -i HEAD~2
1144 test_expect_success 'respect core.abbrev' '
1145 git config core.abbrev 12 &&
1146 set_cat_todo_editor &&
1147 test_must_fail git rebase -i HEAD~4 >todo-list &&
1148 test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1151 test_expect_success 'todo count' '
1152 write_script dump-raw.sh <<-\EOF &&
1153 cat "$1"
1155 test_set_editor "$(pwd)/dump-raw.sh" &&
1156 git rebase -i HEAD~4 >actual &&
1157 test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1160 test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
1161 git checkout --force branch2 &&
1162 git clean -f &&
1163 set_fake_editor &&
1164 FAKE_LINES="edit 1 2" git rebase -i A &&
1165 test_cmp_rev HEAD F &&
1166 test_path_is_missing file6 &&
1167 >file6 &&
1168 test_must_fail git rebase --continue &&
1169 test_cmp_rev HEAD F &&
1170 rm file6 &&
1171 git rebase --continue &&
1172 test_cmp_rev HEAD I
1175 test_expect_success 'rebase -i commits that overwrite untracked files (squash)' '
1176 git checkout --force branch2 &&
1177 git clean -f &&
1178 git tag original-branch2 &&
1179 set_fake_editor &&
1180 FAKE_LINES="edit 1 squash 2" git rebase -i A &&
1181 test_cmp_rev HEAD F &&
1182 test_path_is_missing file6 &&
1183 >file6 &&
1184 test_must_fail git rebase --continue &&
1185 test_cmp_rev HEAD F &&
1186 rm file6 &&
1187 git rebase --continue &&
1188 test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1189 git reset --hard original-branch2
1192 test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
1193 git checkout --force branch2 &&
1194 git clean -f &&
1195 set_fake_editor &&
1196 FAKE_LINES="edit 1 2" git rebase -i --no-ff A &&
1197 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1198 test_path_is_missing file6 &&
1199 >file6 &&
1200 test_must_fail git rebase --continue &&
1201 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1202 rm file6 &&
1203 git rebase --continue &&
1204 test $(git cat-file commit HEAD | sed -ne \$p) = I
1207 test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
1208 git checkout -b commit-to-skip &&
1209 for double in X 3 1
1211 test_seq 5 | sed "s/$double/&&/" >seq &&
1212 git add seq &&
1213 test_tick &&
1214 git commit -m seq-$double
1215 done &&
1216 git tag seq-onto &&
1217 git reset --hard HEAD~2 &&
1218 git cherry-pick seq-onto &&
1219 set_fake_editor &&
1220 test_must_fail env FAKE_LINES= git rebase -i seq-onto &&
1221 test -d .git/rebase-merge &&
1222 git rebase --continue &&
1223 git diff --exit-code seq-onto &&
1224 test ! -d .git/rebase-merge &&
1225 test ! -f .git/CHERRY_PICK_HEAD
1228 rebase_setup_and_clean () {
1229 test_when_finished "
1230 git checkout master &&
1231 test_might_fail git branch -D $1 &&
1232 test_might_fail git rebase --abort
1233 " &&
1234 git checkout -b $1 master
1237 test_expect_success 'drop' '
1238 rebase_setup_and_clean drop-test &&
1239 set_fake_editor &&
1240 FAKE_LINES="1 drop 2 3 drop 4 5" git rebase -i --root &&
1241 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1242 test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1243 test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1246 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
1247 test_config rebase.missingCommitsCheck ignore &&
1248 rebase_setup_and_clean missing-commit &&
1249 set_fake_editor &&
1250 FAKE_LINES="1 2 3 4" \
1251 git rebase -i --root 2>actual &&
1252 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1253 test_i18ngrep \
1254 "Successfully rebased and updated refs/heads/missing-commit" \
1255 actual
1258 cat >expect <<EOF
1259 Warning: some commits may have been dropped accidentally.
1260 Dropped commits (newer to older):
1261 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1262 To avoid this message, use "drop" to explicitly remove a commit.
1264 Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1265 The possible behaviours are: ignore, warn, error.
1267 Rebasing (1/4)
1268 Rebasing (2/4)
1269 Rebasing (3/4)
1270 Rebasing (4/4)
1271 Successfully rebased and updated refs/heads/missing-commit.
1274 cr_to_nl () {
1275 tr '\015' '\012'
1278 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
1279 test_config rebase.missingCommitsCheck warn &&
1280 rebase_setup_and_clean missing-commit &&
1281 set_fake_editor &&
1282 FAKE_LINES="1 2 3 4" \
1283 git rebase -i --root 2>actual.2 &&
1284 cr_to_nl <actual.2 >actual &&
1285 test_i18ncmp expect actual &&
1286 test D = $(git cat-file commit HEAD | sed -ne \$p)
1289 cat >expect <<EOF
1290 Warning: some commits may have been dropped accidentally.
1291 Dropped commits (newer to older):
1292 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1293 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2)
1294 To avoid this message, use "drop" to explicitly remove a commit.
1296 Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1297 The possible behaviours are: ignore, warn, error.
1299 You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1300 Or you can abort the rebase with 'git rebase --abort'.
1303 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
1304 test_config rebase.missingCommitsCheck error &&
1305 rebase_setup_and_clean missing-commit &&
1306 set_fake_editor &&
1307 test_must_fail env FAKE_LINES="1 2 4" \
1308 git rebase -i --root 2>actual &&
1309 test_i18ncmp expect actual &&
1310 cp .git/rebase-merge/git-rebase-todo.backup \
1311 .git/rebase-merge/git-rebase-todo &&
1312 FAKE_LINES="1 2 drop 3 4 drop 5" \
1313 git rebase --edit-todo &&
1314 git rebase --continue &&
1315 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1316 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1319 test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
1320 rebase_setup_and_clean abbrevcmd &&
1321 test_commit "first" file1.txt "first line" first &&
1322 test_commit "second" file1.txt "another line" second &&
1323 test_commit "fixup! first" file2.txt "first line again" first_fixup &&
1324 test_commit "squash! second" file1.txt "another line here" second_squash &&
1325 cat >expected <<-EOF &&
1326 p $(git rev-list --abbrev-commit -1 first) first
1327 f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
1328 x git show HEAD
1329 p $(git rev-list --abbrev-commit -1 second) second
1330 s $(git rev-list --abbrev-commit -1 second_squash) squash! second
1331 x git show HEAD
1333 git checkout abbrevcmd &&
1334 set_cat_todo_editor &&
1335 test_config rebase.abbreviateCommands true &&
1336 test_must_fail git rebase -i --exec "git show HEAD" \
1337 --autosquash master >actual &&
1338 test_cmp expected actual
1341 test_expect_success 'static check of bad command' '
1342 rebase_setup_and_clean bad-cmd &&
1343 set_fake_editor &&
1344 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1345 git rebase -i --root 2>actual &&
1346 test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" actual &&
1347 test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual &&
1348 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
1349 git rebase --continue &&
1350 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1351 test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1354 test_expect_success 'tabs and spaces are accepted in the todolist' '
1355 rebase_setup_and_clean indented-comment &&
1356 write_script add-indent.sh <<-\EOF &&
1358 # Turn single spaces into space/tab mix
1359 sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1360 printf "\n\t# comment\n #more\n\t # comment\n"
1361 ) >"$1.new"
1362 mv "$1.new" "$1"
1364 test_set_editor "$(pwd)/add-indent.sh" &&
1365 git rebase -i HEAD^^^ &&
1366 test E = $(git cat-file commit HEAD | sed -ne \$p)
1369 test_expect_success 'static check of bad SHA-1' '
1370 rebase_setup_and_clean bad-sha &&
1371 set_fake_editor &&
1372 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1373 git rebase -i --root 2>actual &&
1374 test_i18ngrep "edit XXXXXXX False commit" actual &&
1375 test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual &&
1376 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
1377 git rebase --continue &&
1378 test E = $(git cat-file commit HEAD | sed -ne \$p)
1381 test_expect_success 'editor saves as CR/LF' '
1382 git checkout -b with-crlf &&
1383 write_script add-crs.sh <<-\EOF &&
1384 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1385 mv -f "$1".new "$1"
1388 test_set_editor "$(pwd)/add-crs.sh" &&
1389 git rebase -i HEAD^
1393 SQ="'"
1394 test_expect_success 'rebase -i --gpg-sign=<key-id>' '
1395 test_when_finished "test_might_fail git rebase --abort" &&
1396 set_fake_editor &&
1397 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
1398 >out 2>err &&
1399 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1402 test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
1403 test_when_finished "test_might_fail git rebase --abort" &&
1404 test_config commit.gpgsign true &&
1405 set_fake_editor &&
1406 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
1407 >out 2>err &&
1408 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1411 test_done