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