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