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