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