sequencer: pass absolute GIT_DIR to exec commands
[git] / t / t3404-rebase-interactive.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Johannes E. Schindelin
4 #
5
6 test_description='git rebase interactive
7
8 This test runs git rebase "interactively", by faking an edit, and verifies
9 that the result still makes sense.
10
11 Initial setup:
12
13      one - two - three - four (conflict-branch)
14    /
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)
22   \
23     N - O - P                 (no-ff-branch)
24
25  where A, B, D and G all touch file1, and one, two, three, four all
26  touch file "conflict".
27 '
28 . ./test-lib.sh
29
30 . "$TEST_DIRECTORY"/lib-rebase.sh
31
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.
34
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
61 '
62
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
69
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
76 '
77
78 test_expect_success 'rebase -i with the exec command' '
79         git checkout master &&
80         (
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-*
98 '
99
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
109 '
110
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^
119         )
120 '
121
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
129 '
130
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
138 '
139
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)
146 '
147
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)
157 '
158
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)
166 '
167
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)
177 '
178
179 test_expect_success 'reflog for the branch shows state before rebase' '
180         test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
181 '
182
183 test_expect_success 'exchange two commits' '
184         set_fake_editor &&
185         FAKE_LINES="2 1" git rebase -i HEAD~2 &&
186         test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
187         test G = $(git cat-file commit HEAD | sed -ne \$p)
188 '
189
190 cat > expect << EOF
191 diff --git a/file1 b/file1
192 index f70f10e..fd79235 100644
193 --- a/file1
194 +++ b/file1
195 @@ -1 +1 @@
196 -A
197 +G
198 EOF
199
200 cat > expect2 << EOF
201 <<<<<<< HEAD
202 D
203 =======
204 G
205 >>>>>>> 5d18e54... G
206 EOF
207
208 test_expect_success 'stop on conflicting pick' '
209         git tag new-branch1 &&
210         set_fake_editor &&
211         test_must_fail git rebase -i master &&
212         test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
213         test_cmp expect .git/rebase-merge/patch &&
214         test_cmp expect2 file1 &&
215         test "$(git diff --name-status |
216                 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
217         test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
218         test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
219 '
220
221 test_expect_success 'abort' '
222         git rebase --abort &&
223         test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
224         test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
225         test_path_is_missing .git/rebase-merge
226 '
227
228 test_expect_success 'abort with error when new base cannot be checked out' '
229         git rm --cached file1 &&
230         git commit -m "remove file in base" &&
231         set_fake_editor &&
232         test_must_fail git rebase -i master > output 2>&1 &&
233         test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
234                 output &&
235         test_i18ngrep "file1" output &&
236         test_path_is_missing .git/rebase-merge &&
237         git reset --hard HEAD^
238 '
239
240 test_expect_success 'retain authorship' '
241         echo A > file7 &&
242         git add file7 &&
243         test_tick &&
244         GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
245         git tag twerp &&
246         set_fake_editor &&
247         git rebase -i --onto master HEAD^ &&
248         git show HEAD | grep "^Author: Twerp Snog"
249 '
250
251 test_expect_success 'retain authorship w/ conflicts' '
252         git reset --hard twerp &&
253         test_commit a conflict a conflict-a &&
254         git reset --hard twerp &&
255         GIT_AUTHOR_NAME=AttributeMe \
256         test_commit b conflict b conflict-b &&
257         set_fake_editor &&
258         test_must_fail git rebase -i conflict-a &&
259         echo resolved >conflict &&
260         git add conflict &&
261         git rebase --continue &&
262         test $(git rev-parse conflict-a^0) = $(git rev-parse HEAD^) &&
263         git show >out &&
264         grep AttributeMe out
265 '
266
267 test_expect_success 'squash' '
268         git reset --hard twerp &&
269         echo B > file7 &&
270         test_tick &&
271         GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
272         echo "******************************" &&
273         set_fake_editor &&
274         FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
275                 git rebase -i --onto master HEAD~2 &&
276         test B = $(cat file7) &&
277         test $(git rev-parse HEAD^) = $(git rev-parse master)
278 '
279
280 test_expect_success 'retain authorship when squashing' '
281         git show HEAD | grep "^Author: Twerp Snog"
282 '
283
284 test_expect_success '-p handles "no changes" gracefully' '
285         HEAD=$(git rev-parse HEAD) &&
286         set_fake_editor &&
287         git rebase -i -p HEAD^ &&
288         git update-index --refresh &&
289         git diff-files --quiet &&
290         git diff-index --quiet --cached HEAD -- &&
291         test $HEAD = $(git rev-parse HEAD)
292 '
293
294 test_expect_failure 'exchange two commits with -p' '
295         git checkout H &&
296         set_fake_editor &&
297         FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
298         test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
299         test G = $(git cat-file commit HEAD | sed -ne \$p)
300 '
301
302 test_expect_success 'preserve merges with -p' '
303         git checkout -b to-be-preserved master^ &&
304         : > unrelated-file &&
305         git add unrelated-file &&
306         test_tick &&
307         git commit -m "unrelated" &&
308         git checkout -b another-branch master &&
309         echo B > file1 &&
310         test_tick &&
311         git commit -m J file1 &&
312         test_tick &&
313         git merge to-be-preserved &&
314         echo C > file1 &&
315         test_tick &&
316         git commit -m K file1 &&
317         echo D > file1 &&
318         test_tick &&
319         git commit -m L1 file1 &&
320         git checkout HEAD^ &&
321         echo 1 > unrelated-file &&
322         test_tick &&
323         git commit -m L2 unrelated-file &&
324         test_tick &&
325         git merge another-branch &&
326         echo E > file1 &&
327         test_tick &&
328         git commit -m M file1 &&
329         git checkout -b to-be-rebased &&
330         test_tick &&
331         set_fake_editor &&
332         git rebase -i -p --onto branch1 master &&
333         git update-index --refresh &&
334         git diff-files --quiet &&
335         git diff-index --quiet --cached HEAD -- &&
336         test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
337         test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
338         test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
339         test $(git show HEAD~5:file1) = B &&
340         test $(git show HEAD~3:file1) = C &&
341         test $(git show HEAD:file1) = E &&
342         test $(git show HEAD:unrelated-file) = 1
343 '
344
345 test_expect_success 'edit ancestor with -p' '
346         set_fake_editor &&
347         FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
348         echo 2 > unrelated-file &&
349         test_tick &&
350         git commit -m L2-modified --amend unrelated-file &&
351         git rebase --continue &&
352         git update-index --refresh &&
353         git diff-files --quiet &&
354         git diff-index --quiet --cached HEAD -- &&
355         test $(git show HEAD:unrelated-file) = 2
356 '
357
358 test_expect_success '--continue tries to commit' '
359         test_tick &&
360         set_fake_editor &&
361         test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
362         echo resolved > file1 &&
363         git add file1 &&
364         FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
365         test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
366         git show HEAD | grep chouette
367 '
368
369 test_expect_success 'verbose flag is heeded, even after --continue' '
370         git reset --hard master@{1} &&
371         test_tick &&
372         set_fake_editor &&
373         test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
374         echo resolved > file1 &&
375         git add file1 &&
376         git rebase --continue > output &&
377         grep "^ file1 | 2 +-$" output
378 '
379
380 test_expect_success 'multi-squash only fires up editor once' '
381         base=$(git rev-parse HEAD~4) &&
382         set_fake_editor &&
383         FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
384                 EXPECT_HEADER_COUNT=4 \
385                 git rebase -i $base &&
386         test $base = $(git rev-parse HEAD^) &&
387         test 1 = $(git show | grep ONCE | wc -l)
388 '
389
390 test_expect_success 'multi-fixup does not fire up editor' '
391         git checkout -b multi-fixup E &&
392         base=$(git rev-parse HEAD~4) &&
393         set_fake_editor &&
394         FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
395                 git rebase -i $base &&
396         test $base = $(git rev-parse HEAD^) &&
397         test 0 = $(git show | grep NEVER | wc -l) &&
398         git checkout to-be-rebased &&
399         git branch -D multi-fixup
400 '
401
402 test_expect_success 'commit message used after conflict' '
403         git checkout -b conflict-fixup conflict-branch &&
404         base=$(git rev-parse HEAD~4) &&
405         set_fake_editor &&
406         test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base &&
407         echo three > conflict &&
408         git add conflict &&
409         FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
410                 git rebase --continue &&
411         test $base = $(git rev-parse HEAD^) &&
412         test 1 = $(git show | grep ONCE | wc -l) &&
413         git checkout to-be-rebased &&
414         git branch -D conflict-fixup
415 '
416
417 test_expect_success 'commit message retained after conflict' '
418         git checkout -b conflict-squash conflict-branch &&
419         base=$(git rev-parse HEAD~4) &&
420         set_fake_editor &&
421         test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base &&
422         echo three > conflict &&
423         git add conflict &&
424         FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
425                 git rebase --continue &&
426         test $base = $(git rev-parse HEAD^) &&
427         test 2 = $(git show | grep TWICE | wc -l) &&
428         git checkout to-be-rebased &&
429         git branch -D conflict-squash
430 '
431
432 cat > expect-squash-fixup << EOF
433 B
434
435 D
436
437 ONCE
438 EOF
439
440 test_expect_success 'squash and fixup generate correct log messages' '
441         git checkout -b squash-fixup E &&
442         base=$(git rev-parse HEAD~4) &&
443         set_fake_editor &&
444         FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
445                 EXPECT_HEADER_COUNT=4 \
446                 git rebase -i $base &&
447         git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
448         test_cmp expect-squash-fixup actual-squash-fixup &&
449         git checkout to-be-rebased &&
450         git branch -D squash-fixup
451 '
452
453 test_expect_success 'squash ignores comments' '
454         git checkout -b skip-comments E &&
455         base=$(git rev-parse HEAD~4) &&
456         set_fake_editor &&
457         FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
458                 EXPECT_HEADER_COUNT=4 \
459                 git rebase -i $base &&
460         test $base = $(git rev-parse HEAD^) &&
461         test 1 = $(git show | grep ONCE | wc -l) &&
462         git checkout to-be-rebased &&
463         git branch -D skip-comments
464 '
465
466 test_expect_success 'squash ignores blank lines' '
467         git checkout -b skip-blank-lines E &&
468         base=$(git rev-parse HEAD~4) &&
469         set_fake_editor &&
470         FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
471                 EXPECT_HEADER_COUNT=4 \
472                 git rebase -i $base &&
473         test $base = $(git rev-parse HEAD^) &&
474         test 1 = $(git show | grep ONCE | wc -l) &&
475         git checkout to-be-rebased &&
476         git branch -D skip-blank-lines
477 '
478
479 test_expect_success 'squash works as expected' '
480         git checkout -b squash-works no-conflict-branch &&
481         one=$(git rev-parse HEAD~3) &&
482         set_fake_editor &&
483         FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
484                 git rebase -i HEAD~3 &&
485         test $one = $(git rev-parse HEAD~2)
486 '
487
488 test_expect_success 'interrupted squash works as expected' '
489         git checkout -b interrupted-squash conflict-branch &&
490         one=$(git rev-parse HEAD~3) &&
491         set_fake_editor &&
492         test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
493         (echo one; echo two; echo four) > conflict &&
494         git add conflict &&
495         test_must_fail git rebase --continue &&
496         echo resolved > conflict &&
497         git add conflict &&
498         git rebase --continue &&
499         test $one = $(git rev-parse HEAD~2)
500 '
501
502 test_expect_success 'interrupted squash works as expected (case 2)' '
503         git checkout -b interrupted-squash2 conflict-branch &&
504         one=$(git rev-parse HEAD~3) &&
505         set_fake_editor &&
506         test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
507         (echo one; echo four) > conflict &&
508         git add conflict &&
509         test_must_fail git rebase --continue &&
510         (echo one; echo two; echo four) > conflict &&
511         git add conflict &&
512         test_must_fail git rebase --continue &&
513         echo resolved > conflict &&
514         git add conflict &&
515         git rebase --continue &&
516         test $one = $(git rev-parse HEAD~2)
517 '
518
519 test_expect_success '--continue tries to commit, even for "edit"' '
520         echo unrelated > file7 &&
521         git add file7 &&
522         test_tick &&
523         git commit -m "unrelated change" &&
524         parent=$(git rev-parse HEAD^) &&
525         test_tick &&
526         set_fake_editor &&
527         FAKE_LINES="edit 1" git rebase -i HEAD^ &&
528         echo edited > file7 &&
529         git add file7 &&
530         FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
531         test edited = $(git show HEAD:file7) &&
532         git show HEAD | grep chouette &&
533         test $parent = $(git rev-parse HEAD^)
534 '
535
536 test_expect_success 'aborted --continue does not squash commits after "edit"' '
537         old=$(git rev-parse HEAD) &&
538         test_tick &&
539         set_fake_editor &&
540         FAKE_LINES="edit 1" git rebase -i HEAD^ &&
541         echo "edited again" > file7 &&
542         git add file7 &&
543         test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue &&
544         test $old = $(git rev-parse HEAD) &&
545         git rebase --abort
546 '
547
548 test_expect_success 'auto-amend only edited commits after "edit"' '
549         test_tick &&
550         set_fake_editor &&
551         FAKE_LINES="edit 1" git rebase -i HEAD^ &&
552         echo "edited again" > file7 &&
553         git add file7 &&
554         FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
555         echo "and again" > file7 &&
556         git add file7 &&
557         test_tick &&
558         test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue &&
559         git rebase --abort
560 '
561
562 test_expect_success 'clean error after failed "exec"' '
563         test_tick &&
564         test_when_finished "git rebase --abort || :" &&
565         set_fake_editor &&
566         test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ &&
567         echo "edited again" > file7 &&
568         git add file7 &&
569         test_must_fail git rebase --continue 2>error &&
570         test_i18ngrep "you have staged changes in your working tree" error
571 '
572
573 test_expect_success 'rebase a detached HEAD' '
574         grandparent=$(git rev-parse HEAD~2) &&
575         git checkout $(git rev-parse HEAD) &&
576         test_tick &&
577         set_fake_editor &&
578         FAKE_LINES="2 1" git rebase -i HEAD~2 &&
579         test $grandparent = $(git rev-parse HEAD~2)
580 '
581
582 test_expect_success 'rebase a commit violating pre-commit' '
583
584         mkdir -p .git/hooks &&
585         write_script .git/hooks/pre-commit <<-\EOF &&
586         test -z "$(git diff --cached --check)"
587         EOF
588         echo "monde! " >> file1 &&
589         test_tick &&
590         test_must_fail git commit -m doesnt-verify file1 &&
591         git commit -m doesnt-verify --no-verify file1 &&
592         test_tick &&
593         set_fake_editor &&
594         FAKE_LINES=2 git rebase -i HEAD~2
595
596 '
597
598 test_expect_success 'rebase with a file named HEAD in worktree' '
599
600         rm -fr .git/hooks &&
601         git reset --hard &&
602         git checkout -b branch3 A &&
603
604         (
605                 GIT_AUTHOR_NAME="Squashed Away" &&
606                 export GIT_AUTHOR_NAME &&
607                 >HEAD &&
608                 git add HEAD &&
609                 git commit -m "Add head" &&
610                 >BODY &&
611                 git add BODY &&
612                 git commit -m "Add body"
613         ) &&
614
615         set_fake_editor &&
616         FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
617         test "$(git show -s --pretty=format:%an)" = "Squashed Away"
618
619 '
620
621 test_expect_success 'do "noop" when there is nothing to cherry-pick' '
622
623         git checkout -b branch4 HEAD &&
624         GIT_EDITOR=: git commit --amend \
625                 --author="Somebody else <somebody@else.com>" &&
626         test $(git rev-parse branch3) != $(git rev-parse branch4) &&
627         set_fake_editor &&
628         git rebase -i branch3 &&
629         test $(git rev-parse branch3) = $(git rev-parse branch4)
630
631 '
632
633 test_expect_success 'submodule rebase setup' '
634         git checkout A &&
635         mkdir sub &&
636         (
637                 cd sub && git init && >elif &&
638                 git add elif && git commit -m "submodule initial"
639         ) &&
640         echo 1 >file1 &&
641         git add file1 sub &&
642         test_tick &&
643         git commit -m "One" &&
644         echo 2 >file1 &&
645         test_tick &&
646         git commit -a -m "Two" &&
647         (
648                 cd sub && echo 3 >elif &&
649                 git commit -a -m "submodule second"
650         ) &&
651         test_tick &&
652         set_fake_editor &&
653         git commit -a -m "Three changes submodule"
654 '
655
656 test_expect_success 'submodule rebase -i' '
657         set_fake_editor &&
658         FAKE_LINES="1 squash 2 3" git rebase -i A
659 '
660
661 test_expect_success 'submodule conflict setup' '
662         git tag submodule-base &&
663         git checkout HEAD^ &&
664         (
665                 cd sub && git checkout HEAD^ && echo 4 >elif &&
666                 git add elif && git commit -m "submodule conflict"
667         ) &&
668         git add sub &&
669         test_tick &&
670         git commit -m "Conflict in submodule" &&
671         git tag submodule-topic
672 '
673
674 test_expect_success 'rebase -i continue with only submodule staged' '
675         set_fake_editor &&
676         test_must_fail git rebase -i submodule-base &&
677         git add sub &&
678         git rebase --continue &&
679         test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
680 '
681
682 test_expect_success 'rebase -i continue with unstaged submodule' '
683         git checkout submodule-topic &&
684         git reset --hard &&
685         set_fake_editor &&
686         test_must_fail git rebase -i submodule-base &&
687         git reset &&
688         git rebase --continue &&
689         test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
690 '
691
692 test_expect_success 'avoid unnecessary reset' '
693         git checkout master &&
694         git reset --hard &&
695         test-chmtime =123456789 file3 &&
696         git update-index --refresh &&
697         HEAD=$(git rev-parse HEAD) &&
698         set_fake_editor &&
699         git rebase -i HEAD~4 &&
700         test $HEAD = $(git rev-parse HEAD) &&
701         MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
702         test 123456789 = $MTIME
703 '
704
705 test_expect_success 'reword' '
706         git checkout -b reword-branch master &&
707         set_fake_editor &&
708         FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
709         git show HEAD | grep "E changed" &&
710         test $(git rev-parse master) != $(git rev-parse HEAD) &&
711         test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
712         FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
713         git show HEAD^ | grep "D changed" &&
714         FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
715         git show HEAD~3 | grep "B changed" &&
716         FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
717         git show HEAD~2 | grep "C changed"
718 '
719
720 test_expect_success 'rebase -i can copy notes' '
721         git config notes.rewrite.rebase true &&
722         git config notes.rewriteRef "refs/notes/*" &&
723         test_commit n1 &&
724         test_commit n2 &&
725         test_commit n3 &&
726         git notes add -m"a note" n3 &&
727         set_fake_editor &&
728         git rebase -i --onto n1 n2 &&
729         test "a note" = "$(git notes show HEAD)"
730 '
731
732 cat >expect <<EOF
733 an earlier note
734
735 a note
736 EOF
737
738 test_expect_success 'rebase -i can copy notes over a fixup' '
739         git reset --hard n3 &&
740         git notes add -m"an earlier note" n2 &&
741         set_fake_editor &&
742         GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
743         git notes show > output &&
744         test_cmp expect output
745 '
746
747 test_expect_success 'rebase while detaching HEAD' '
748         git symbolic-ref HEAD &&
749         grandparent=$(git rev-parse HEAD~2) &&
750         test_tick &&
751         set_fake_editor &&
752         FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
753         test $grandparent = $(git rev-parse HEAD~2) &&
754         test_must_fail git symbolic-ref HEAD
755 '
756
757 test_tick # Ensure that the rebased commits get a different timestamp.
758 test_expect_success 'always cherry-pick with --no-ff' '
759         git checkout no-ff-branch &&
760         git tag original-no-ff-branch &&
761         set_fake_editor &&
762         git rebase -i --no-ff A &&
763         touch empty &&
764         for p in 0 1 2
765         do
766                 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
767                 git diff HEAD~$p original-no-ff-branch~$p > out &&
768                 test_cmp empty out
769         done &&
770         test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
771         git diff HEAD~3 original-no-ff-branch~3 > out &&
772         test_cmp empty out
773 '
774
775 test_expect_success 'set up commits with funny messages' '
776         git checkout -b funny A &&
777         echo >>file1 &&
778         test_tick &&
779         git commit -a -m "end with slash\\" &&
780         echo >>file1 &&
781         test_tick &&
782         git commit -a -m "something (\000) that looks like octal" &&
783         echo >>file1 &&
784         test_tick &&
785         git commit -a -m "something (\n) that looks like a newline" &&
786         echo >>file1 &&
787         test_tick &&
788         git commit -a -m "another commit"
789 '
790
791 test_expect_success 'rebase-i history with funny messages' '
792         git rev-list A..funny >expect &&
793         test_tick &&
794         set_fake_editor &&
795         FAKE_LINES="1 2 3 4" git rebase -i A &&
796         git rev-list A.. >actual &&
797         test_cmp expect actual
798 '
799
800 test_expect_success 'prepare for rebase -i --exec' '
801         git checkout master &&
802         git checkout -b execute &&
803         test_commit one_exec main.txt one_exec &&
804         test_commit two_exec main.txt two_exec &&
805         test_commit three_exec main.txt three_exec
806 '
807
808 test_expect_success 'running "git rebase -i --exec git show HEAD"' '
809         set_fake_editor &&
810         git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
811         (
812                 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
813                 export FAKE_LINES &&
814                 git rebase -i HEAD~2 >expect
815         ) &&
816         sed -e "1,9d" expect >expected &&
817         test_cmp expected actual
818 '
819
820 test_expect_success 'running "git rebase --exec git show HEAD -i"' '
821         git reset --hard execute &&
822         set_fake_editor &&
823         git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
824         (
825                 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
826                 export FAKE_LINES &&
827                 git rebase -i HEAD~2 >expect
828         ) &&
829         sed -e "1,9d" expect >expected &&
830         test_cmp expected actual
831 '
832
833 test_expect_success 'running "git rebase -ix git show HEAD"' '
834         git reset --hard execute &&
835         set_fake_editor &&
836         git rebase -ix "git show HEAD" HEAD~2 >actual &&
837         (
838                 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
839                 export FAKE_LINES &&
840                 git rebase -i HEAD~2 >expect
841         ) &&
842         sed -e "1,9d" expect >expected &&
843         test_cmp expected actual
844 '
845
846
847 test_expect_success 'rebase -ix with several <CMD>' '
848         git reset --hard execute &&
849         set_fake_editor &&
850         git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
851         (
852                 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
853                 export FAKE_LINES &&
854                 git rebase -i HEAD~2 >expect
855         ) &&
856         sed -e "1,9d" expect >expected &&
857         test_cmp expected actual
858 '
859
860 test_expect_success 'rebase -ix with several instances of --exec' '
861         git reset --hard execute &&
862         set_fake_editor &&
863         git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
864         (
865                 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
866                                 exec_git_show_HEAD exec_pwd" &&
867                 export FAKE_LINES &&
868                 git rebase -i HEAD~2 >expect
869         ) &&
870         sed -e "1,11d" expect >expected &&
871         test_cmp expected actual
872 '
873
874 test_expect_success 'rebase -ix with --autosquash' '
875         git reset --hard execute &&
876         git checkout -b autosquash &&
877         echo second >second.txt &&
878         git add second.txt &&
879         git commit -m "fixup! two_exec" &&
880         echo bis >bis.txt &&
881         git add bis.txt &&
882         git commit -m "fixup! two_exec" &&
883         set_fake_editor &&
884         (
885                 git checkout -b autosquash_actual &&
886                 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
887         ) &&
888         git checkout autosquash &&
889         (
890                 git checkout -b autosquash_expected &&
891                 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
892                 export FAKE_LINES &&
893                 git rebase -i HEAD~4 >expect
894         ) &&
895         sed -e "1,13d" expect >expected &&
896         test_cmp expected actual
897 '
898
899 test_expect_success 'rebase --exec works without -i ' '
900         git reset --hard execute &&
901         rm -rf exec_output &&
902         EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output"  HEAD~2 2>actual &&
903         test_i18ngrep  "Successfully rebased and updated" actual &&
904         test_line_count = 2 exec_output &&
905         test_path_is_missing invoked_editor
906 '
907
908 test_expect_success 'rebase -i --exec without <CMD>' '
909         git reset --hard execute &&
910         set_fake_editor &&
911         test_must_fail git rebase -i --exec 2>tmp &&
912         sed -e "1d" tmp >actual &&
913         test_must_fail git rebase -h >expected &&
914         test_cmp expected actual &&
915         git checkout master
916 '
917
918 test_expect_success 'rebase -i --root re-order and drop commits' '
919         git checkout E &&
920         set_fake_editor &&
921         FAKE_LINES="3 1 2 5" git rebase -i --root &&
922         test E = $(git cat-file commit HEAD | sed -ne \$p) &&
923         test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
924         test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
925         test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
926         test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
927 '
928
929 test_expect_success 'rebase -i --root retain root commit author and message' '
930         git checkout A &&
931         echo B >file7 &&
932         git add file7 &&
933         GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
934         set_fake_editor &&
935         FAKE_LINES="2" git rebase -i --root &&
936         git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
937         git cat-file commit HEAD | grep -q "^different author$"
938 '
939
940 test_expect_success 'rebase -i --root temporary sentinel commit' '
941         git checkout B &&
942         set_fake_editor &&
943         test_must_fail env FAKE_LINES="2" git rebase -i --root &&
944         git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
945         git rebase --abort
946 '
947
948 test_expect_success 'rebase -i --root fixup root commit' '
949         git checkout B &&
950         set_fake_editor &&
951         FAKE_LINES="1 fixup 2" git rebase -i --root &&
952         test A = $(git cat-file commit HEAD | sed -ne \$p) &&
953         test B = $(git show HEAD:file1) &&
954         test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
955 '
956
957 test_expect_success 'rebase --edit-todo does not works on non-interactive rebase' '
958         git reset --hard &&
959         git checkout conflict-branch &&
960         set_fake_editor &&
961         test_must_fail git rebase --onto HEAD~2 HEAD~ &&
962         test_must_fail git rebase --edit-todo &&
963         git rebase --abort
964 '
965
966 test_expect_success 'rebase --edit-todo can be used to modify todo' '
967         git reset --hard &&
968         git checkout no-conflict-branch^0 &&
969         set_fake_editor &&
970         FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
971         FAKE_LINES="2 1" git rebase --edit-todo &&
972         git rebase --continue &&
973         test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
974         test L = $(git cat-file commit HEAD | sed -ne \$p)
975 '
976
977 test_expect_success 'rebase -i produces readable reflog' '
978         git reset --hard &&
979         git branch -f branch-reflog-test H &&
980         set_fake_editor &&
981         git rebase -i --onto I F branch-reflog-test &&
982         cat >expect <<-\EOF &&
983         rebase -i (finish): returning to refs/heads/branch-reflog-test
984         rebase -i (pick): H
985         rebase -i (pick): G
986         rebase -i (start): checkout I
987         EOF
988         git reflog -n4 HEAD |
989         sed "s/[^:]*: //" >actual &&
990         test_cmp expect actual
991 '
992
993 test_expect_success 'rebase -i respects core.commentchar' '
994         git reset --hard &&
995         git checkout E^0 &&
996         test_config core.commentchar "\\" &&
997         write_script remove-all-but-first.sh <<-\EOF &&
998         sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
999         mv "$1.tmp" "$1"
1000         EOF
1001         test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1002         git rebase -i B &&
1003         test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1004 '
1005
1006 test_expect_success 'rebase -i respects core.commentchar=auto' '
1007         test_config core.commentchar auto &&
1008         write_script copy-edit-script.sh <<-\EOF &&
1009         cp "$1" edit-script
1010         EOF
1011         test_set_editor "$(pwd)/copy-edit-script.sh" &&
1012         test_when_finished "git rebase --abort || :" &&
1013         git rebase -i HEAD^ &&
1014         test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1015 '
1016
1017 test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1018         test_when_finished "git branch -D torebase" &&
1019         git checkout -b torebase branch1 &&
1020         upstream=$(git rev-parse ":/J") &&
1021         onto=$(git rev-parse ":/A") &&
1022         git rebase --onto $onto $upstream &&
1023         git reset --hard branch1 &&
1024         git rebase --onto ":/A" ":/J" &&
1025         git checkout branch1
1026 '
1027
1028 test_expect_success 'rebase -i with --strategy and -X' '
1029         git checkout -b conflict-merge-use-theirs conflict-branch &&
1030         git reset --hard HEAD^ &&
1031         echo five >conflict &&
1032         echo Z >file1 &&
1033         git commit -a -m "one file conflict" &&
1034         EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1035         test $(git show conflict-branch:conflict) = $(cat conflict) &&
1036         test $(cat file1) = Z
1037 '
1038
1039 test_expect_success 'interrupted rebase -i with --strategy and -X' '
1040         git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1041         git reset --hard HEAD^ &&
1042         >breakpoint &&
1043         git add breakpoint &&
1044         git commit -m "breakpoint for interactive mode" &&
1045         echo five >conflict &&
1046         echo Z >file1 &&
1047         git commit -a -m "one file conflict" &&
1048         set_fake_editor &&
1049         FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive -Xours conflict-branch &&
1050         git rebase --continue &&
1051         test $(git show conflict-branch:conflict) = $(cat conflict) &&
1052         test $(cat file1) = Z
1053 '
1054
1055 test_expect_success 'rebase -i error on commits with \ in message' '
1056         current_head=$(git rev-parse HEAD) &&
1057         test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1058         test_commit TO-REMOVE will-conflict old-content &&
1059         test_commit "\temp" will-conflict new-content dummy &&
1060         test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1061         test_expect_code 1 grep  "      emp" error
1062 '
1063
1064 test_expect_success 'short SHA-1 setup' '
1065         test_when_finished "git checkout master" &&
1066         git checkout --orphan collide &&
1067         git rm -rf . &&
1068         (
1069         unset test_tick &&
1070         test_commit collide1 collide &&
1071         test_commit --notick collide2 collide &&
1072         test_commit --notick collide3 collide
1073         )
1074 '
1075
1076 test_expect_success 'short SHA-1 collide' '
1077         test_when_finished "reset_rebase && git checkout master" &&
1078         git checkout collide &&
1079         (
1080         unset test_tick &&
1081         test_tick &&
1082         set_fake_editor &&
1083         FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1084         FAKE_LINES="reword 1 2" git rebase -i HEAD~2
1085         )
1086 '
1087
1088 test_expect_success 'respect core.abbrev' '
1089         git config core.abbrev 12 &&
1090         set_cat_todo_editor &&
1091         test_must_fail git rebase -i HEAD~4 >todo-list &&
1092         test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1093 '
1094
1095 test_expect_success 'todo count' '
1096         write_script dump-raw.sh <<-\EOF &&
1097                 cat "$1"
1098         EOF
1099         test_set_editor "$(pwd)/dump-raw.sh" &&
1100         git rebase -i HEAD~4 >actual &&
1101         test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1102 '
1103
1104 test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
1105         git checkout --force branch2 &&
1106         git clean -f &&
1107         set_fake_editor &&
1108         FAKE_LINES="edit 1 2" git rebase -i A &&
1109         test_cmp_rev HEAD F &&
1110         test_path_is_missing file6 &&
1111         >file6 &&
1112         test_must_fail git rebase --continue &&
1113         test_cmp_rev HEAD F &&
1114         rm file6 &&
1115         git rebase --continue &&
1116         test_cmp_rev HEAD I
1117 '
1118
1119 test_expect_success 'rebase -i commits that overwrite untracked files (squash)' '
1120         git checkout --force branch2 &&
1121         git clean -f &&
1122         git tag original-branch2 &&
1123         set_fake_editor &&
1124         FAKE_LINES="edit 1 squash 2" git rebase -i A &&
1125         test_cmp_rev HEAD F &&
1126         test_path_is_missing file6 &&
1127         >file6 &&
1128         test_must_fail git rebase --continue &&
1129         test_cmp_rev HEAD F &&
1130         rm file6 &&
1131         git rebase --continue &&
1132         test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1133         git reset --hard original-branch2
1134 '
1135
1136 test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
1137         git checkout --force branch2 &&
1138         git clean -f &&
1139         set_fake_editor &&
1140         FAKE_LINES="edit 1 2" git rebase -i --no-ff A &&
1141         test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1142         test_path_is_missing file6 &&
1143         >file6 &&
1144         test_must_fail git rebase --continue &&
1145         test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1146         rm file6 &&
1147         git rebase --continue &&
1148         test $(git cat-file commit HEAD | sed -ne \$p) = I
1149 '
1150
1151 test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
1152         git checkout -b commit-to-skip &&
1153         for double in X 3 1
1154         do
1155                 test_seq 5 | sed "s/$double/&&/" >seq &&
1156                 git add seq &&
1157                 test_tick &&
1158                 git commit -m seq-$double
1159         done &&
1160         git tag seq-onto &&
1161         git reset --hard HEAD~2 &&
1162         git cherry-pick seq-onto &&
1163         set_fake_editor &&
1164         test_must_fail env FAKE_LINES= git rebase -i seq-onto &&
1165         test -d .git/rebase-merge &&
1166         git rebase --continue &&
1167         git diff --exit-code seq-onto &&
1168         test ! -d .git/rebase-merge &&
1169         test ! -f .git/CHERRY_PICK_HEAD
1170 '
1171
1172 rebase_setup_and_clean () {
1173         test_when_finished "
1174                 git checkout master &&
1175                 test_might_fail git branch -D $1 &&
1176                 test_might_fail git rebase --abort
1177         " &&
1178         git checkout -b $1 master
1179 }
1180
1181 test_expect_success 'drop' '
1182         rebase_setup_and_clean drop-test &&
1183         set_fake_editor &&
1184         FAKE_LINES="1 drop 2 3 drop 4 5" git rebase -i --root &&
1185         test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1186         test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1187         test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1188 '
1189
1190 cat >expect <<EOF
1191 Successfully rebased and updated refs/heads/missing-commit.
1192 EOF
1193
1194 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
1195         test_config rebase.missingCommitsCheck ignore &&
1196         rebase_setup_and_clean missing-commit &&
1197         set_fake_editor &&
1198         FAKE_LINES="1 2 3 4" \
1199                 git rebase -i --root 2>actual &&
1200         test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1201         test_i18ncmp expect actual
1202 '
1203
1204 cat >expect <<EOF
1205 Warning: some commits may have been dropped accidentally.
1206 Dropped commits (newer to older):
1207  - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1208 To avoid this message, use "drop" to explicitly remove a commit.
1209
1210 Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1211 The possible behaviours are: ignore, warn, error.
1212
1213 Successfully rebased and updated refs/heads/missing-commit.
1214 EOF
1215
1216 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
1217         test_config rebase.missingCommitsCheck warn &&
1218         rebase_setup_and_clean missing-commit &&
1219         set_fake_editor &&
1220         FAKE_LINES="1 2 3 4" \
1221                 git rebase -i --root 2>actual &&
1222         test_i18ncmp expect actual &&
1223         test D = $(git cat-file commit HEAD | sed -ne \$p)
1224 '
1225
1226 cat >expect <<EOF
1227 Warning: some commits may have been dropped accidentally.
1228 Dropped commits (newer to older):
1229  - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1230  - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2)
1231 To avoid this message, use "drop" to explicitly remove a commit.
1232
1233 Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1234 The possible behaviours are: ignore, warn, error.
1235
1236 You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1237 Or you can abort the rebase with 'git rebase --abort'.
1238 EOF
1239
1240 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
1241         test_config rebase.missingCommitsCheck error &&
1242         rebase_setup_and_clean missing-commit &&
1243         set_fake_editor &&
1244         test_must_fail env FAKE_LINES="1 2 4" \
1245                 git rebase -i --root 2>actual &&
1246         test_i18ncmp expect actual &&
1247         cp .git/rebase-merge/git-rebase-todo.backup \
1248                 .git/rebase-merge/git-rebase-todo &&
1249         FAKE_LINES="1 2 drop 3 4 drop 5" \
1250                 git rebase --edit-todo &&
1251         git rebase --continue &&
1252         test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1253         test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1254 '
1255
1256 cat >expect <<EOF
1257 Warning: the command isn't recognized in the following line:
1258  - badcmd $(git rev-list --oneline -1 master~1)
1259
1260 You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1261 Or you can abort the rebase with 'git rebase --abort'.
1262 EOF
1263
1264 test_expect_success 'static check of bad command' '
1265         rebase_setup_and_clean bad-cmd &&
1266         set_fake_editor &&
1267         test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1268                 git rebase -i --root 2>actual &&
1269         test_i18ncmp expect actual &&
1270         FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
1271         git rebase --continue &&
1272         test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1273         test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1274 '
1275
1276 test_expect_success 'tabs and spaces are accepted in the todolist' '
1277         rebase_setup_and_clean indented-comment &&
1278         write_script add-indent.sh <<-\EOF &&
1279         (
1280                 # Turn single spaces into space/tab mix
1281                 sed "1s/ /      /g; 2s/ /  /g; 3s/ /    /g" "$1"
1282                 printf "\n\t# comment\n #more\n\t # comment\n"
1283         ) >"$1.new"
1284         mv "$1.new" "$1"
1285         EOF
1286         test_set_editor "$(pwd)/add-indent.sh" &&
1287         git rebase -i HEAD^^^ &&
1288         test E = $(git cat-file commit HEAD | sed -ne \$p)
1289 '
1290
1291 cat >expect <<EOF
1292 Warning: the SHA-1 is missing or isn't a commit in the following line:
1293  - edit XXXXXXX False commit
1294
1295 You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1296 Or you can abort the rebase with 'git rebase --abort'.
1297 EOF
1298
1299 test_expect_success 'static check of bad SHA-1' '
1300         rebase_setup_and_clean bad-sha &&
1301         set_fake_editor &&
1302         test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1303                 git rebase -i --root 2>actual &&
1304         test_i18ncmp expect actual &&
1305         FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
1306         git rebase --continue &&
1307         test E = $(git cat-file commit HEAD | sed -ne \$p)
1308 '
1309
1310 test_expect_success 'editor saves as CR/LF' '
1311         git checkout -b with-crlf &&
1312         write_script add-crs.sh <<-\EOF &&
1313         sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1314         mv -f "$1".new "$1"
1315         EOF
1316         (
1317                 test_set_editor "$(pwd)/add-crs.sh" &&
1318                 git rebase -i HEAD^
1319         )
1320 '
1321
1322 SQ="'"
1323 test_expect_success 'rebase -i --gpg-sign=<key-id>' '
1324         set_fake_editor &&
1325         FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
1326                 >out 2>err &&
1327         test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1328 '
1329
1330 test_done