unpack_trees: group error messages by type
[git/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.
10'
11. ./test-lib.sh
12
eaf0551d 13. "$TEST_DIRECTORY"/lib-rebase.sh
29a03348
JS
14
15set_fake_editor
16
6c4c44c4 17# Set up the repository like this:
1b1dce4b 18#
6c4c44c4
MH
19# one - two - three - four (conflict-branch)
20# /
21# A - B - C - D - E (master)
22# | \
23# | F - G - H (branch1)
24# | \
b4995494
MB
25# |\ I (branch2)
26# | \
27# | J - K - L - M (no-conflict-branch)
28# \
29# N - O - P (no-ff-branch)
1b1dce4b 30#
6c4c44c4
MH
31# where A, B, D and G all touch file1, and one, two, three, four all
32# touch file "conflict".
b4995494
MB
33#
34# WARNING: Modifications to the initial repository can change the SHA ID used
35# in the expect2 file for the 'stop on conflicting pick' test.
36
1b1dce4b
JS
37
38test_expect_success 'setup' '
163f3925
MH
39 test_commit A file1 &&
40 test_commit B file1 &&
41 test_commit C file2 &&
42 test_commit D file1 &&
43 test_commit E file3 &&
1b1dce4b 44 git checkout -b branch1 A &&
163f3925
MH
45 test_commit F file4 &&
46 test_commit G file1 &&
47 test_commit H file5 &&
1b1dce4b 48 git checkout -b branch2 F &&
163f3925 49 test_commit I file6
6c4c44c4
MH
50 git checkout -b conflict-branch A &&
51 for n in one two three four
52 do
53 test_commit $n conflict
54 done &&
55 git checkout -b no-conflict-branch A &&
56 for n in J K L M
b4995494
MB
57 do
58 test_commit $n file$n
59 done &&
60 git checkout -b no-ff-branch A &&
61 for n in N O P
6c4c44c4
MH
62 do
63 test_commit $n file$n
64 done
1b1dce4b
JS
65'
66
1b1dce4b 67test_expect_success 'no changes are a nop' '
6c4c44c4 68 git checkout branch2 &&
1b1dce4b 69 git rebase -i F &&
ab736792 70 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
1b1dce4b
JS
71 test $(git rev-parse I) = $(git rev-parse HEAD)
72'
73
c9e65892
JS
74test_expect_success 'test the [branch] option' '
75 git checkout -b dead-end &&
76 git rm file6 &&
77 git commit -m "stop here" &&
78 git rebase -i F branch2 &&
ab736792
SB
79 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
80 test $(git rev-parse I) = $(git rev-parse branch2) &&
c9e65892
JS
81 test $(git rev-parse I) = $(git rev-parse HEAD)
82'
83
ab736792
SB
84test_expect_success 'test --onto <branch>' '
85 git checkout -b test-onto branch2 &&
86 git rebase -i --onto branch1 F &&
87 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
88 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
89 test $(git rev-parse I) = $(git rev-parse branch2)
90'
91
1b1dce4b
JS
92test_expect_success 'rebase on top of a non-conflicting commit' '
93 git checkout branch1 &&
94 git tag original-branch1 &&
95 git rebase -i branch2 &&
96 test file6 = $(git diff --name-only original-branch1) &&
ab736792
SB
97 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
98 test $(git rev-parse I) = $(git rev-parse branch2) &&
1b1dce4b
JS
99 test $(git rev-parse I) = $(git rev-parse HEAD~2)
100'
101
68a163c9
JS
102test_expect_success 'reflog for the branch shows state before rebase' '
103 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
104'
105
1b1dce4b
JS
106test_expect_success 'exchange two commits' '
107 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
b4ce54fc
JK
108 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
109 test G = $(git cat-file commit HEAD | sed -ne \$p)
1b1dce4b
JS
110'
111
112cat > expect << EOF
113diff --git a/file1 b/file1
163f3925 114index f70f10e..fd79235 100644
1b1dce4b
JS
115--- a/file1
116+++ b/file1
163f3925
MH
117@@ -1 +1 @@
118-A
119+G
1b1dce4b
JS
120EOF
121
122cat > expect2 << EOF
606475f3 123<<<<<<< HEAD
163f3925 124D
1b1dce4b 125=======
163f3925 126G
b4995494 127>>>>>>> 5d18e54... G
1b1dce4b
JS
128EOF
129
130test_expect_success 'stop on conflicting pick' '
131 git tag new-branch1 &&
ab736792
SB
132 test_must_fail git rebase -i master &&
133 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
28ed6e7b 134 test_cmp expect .git/rebase-merge/patch &&
82ebb0b6 135 test_cmp expect2 file1 &&
0cb0e143 136 test "$(git diff --name-status |
ab736792 137 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
28ed6e7b
JS
138 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
139 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
1b1dce4b
JS
140'
141
142test_expect_success 'abort' '
143 git rebase --abort &&
144 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
ab736792 145 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
28ed6e7b 146 ! test -d .git/rebase-merge
1b1dce4b
JS
147'
148
b096374f
IWC
149test_expect_success 'abort with error when new base cannot be checked out' '
150 git rm --cached file1 &&
151 git commit -m "remove file in base" &&
152 test_must_fail git rebase -i master > output 2>&1 &&
e6c111b4 153 grep "The following untracked working tree files would be overwritten by checkout:" \
b096374f 154 output &&
e6c111b4 155 grep "file1" output &&
b096374f
IWC
156 ! test -d .git/rebase-merge &&
157 git reset --hard HEAD^
158'
159
1b1dce4b
JS
160test_expect_success 'retain authorship' '
161 echo A > file7 &&
162 git add file7 &&
c54b7817 163 test_tick &&
1b1dce4b
JS
164 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
165 git tag twerp &&
166 git rebase -i --onto master HEAD^ &&
167 git show HEAD | grep "^Author: Twerp Snog"
168'
169
170test_expect_success 'squash' '
171 git reset --hard twerp &&
172 echo B > file7 &&
c54b7817 173 test_tick &&
1b1dce4b
JS
174 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
175 echo "******************************" &&
5065ed29 176 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
959c0d06 177 git rebase -i --onto master HEAD~2 &&
1b1dce4b
JS
178 test B = $(cat file7) &&
179 test $(git rev-parse HEAD^) = $(git rev-parse master)
180'
181
182test_expect_success 'retain authorship when squashing' '
81ab1cb4 183 git show HEAD | grep "^Author: Twerp Snog"
1b1dce4b
JS
184'
185
34454e85
JS
186test_expect_success '-p handles "no changes" gracefully' '
187 HEAD=$(git rev-parse HEAD) &&
188 git rebase -i -p HEAD^ &&
71d9451e
TR
189 git update-index --refresh &&
190 git diff-files --quiet &&
191 git diff-index --quiet --cached HEAD -- &&
34454e85
JS
192 test $HEAD = $(git rev-parse HEAD)
193'
194
cddb42d2
JN
195test_expect_failure 'exchange two commits with -p' '
196 FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
197 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
198 test G = $(git cat-file commit HEAD | sed -ne \$p)
199'
200
f09c9b8c
JS
201test_expect_success 'preserve merges with -p' '
202 git checkout -b to-be-preserved master^ &&
203 : > unrelated-file &&
204 git add unrelated-file &&
205 test_tick &&
206 git commit -m "unrelated" &&
5352a82b 207 git checkout -b another-branch master &&
f09c9b8c
JS
208 echo B > file1 &&
209 test_tick &&
210 git commit -m J file1 &&
211 test_tick &&
212 git merge to-be-preserved &&
213 echo C > file1 &&
214 test_tick &&
215 git commit -m K file1 &&
5352a82b
SB
216 echo D > file1 &&
217 test_tick &&
218 git commit -m L1 file1 &&
219 git checkout HEAD^ &&
220 echo 1 > unrelated-file &&
221 test_tick &&
222 git commit -m L2 unrelated-file &&
223 test_tick &&
224 git merge another-branch &&
225 echo E > file1 &&
226 test_tick &&
227 git commit -m M file1 &&
228 git checkout -b to-be-rebased &&
18640d99 229 test_tick &&
f09c9b8c 230 git rebase -i -p --onto branch1 master &&
71d9451e
TR
231 git update-index --refresh &&
232 git diff-files --quiet &&
233 git diff-index --quiet --cached HEAD -- &&
5352a82b
SB
234 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
235 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
236 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
237 test $(git show HEAD~5:file1) = B &&
238 test $(git show HEAD~3:file1) = C &&
239 test $(git show HEAD:file1) = E &&
240 test $(git show HEAD:unrelated-file) = 1
f09c9b8c
JS
241'
242
a96dc01e
TR
243test_expect_success 'edit ancestor with -p' '
244 FAKE_LINES="1 edit 2 3 4" git rebase -i -p HEAD~3 &&
245 echo 2 > unrelated-file &&
246 test_tick &&
247 git commit -m L2-modified --amend unrelated-file &&
248 git rebase --continue &&
249 git update-index --refresh &&
250 git diff-files --quiet &&
251 git diff-index --quiet --cached HEAD -- &&
252 test $(git show HEAD:unrelated-file) = 2
253'
254
18640d99
JS
255test_expect_success '--continue tries to commit' '
256 test_tick &&
ab736792 257 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
18640d99
JS
258 echo resolved > file1 &&
259 git add file1 &&
260 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
261 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
262 git show HEAD | grep chouette
263'
264
8e4a91bd
JS
265test_expect_success 'verbose flag is heeded, even after --continue' '
266 git reset --hard HEAD@{1} &&
267 test_tick &&
ab736792 268 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
8e4a91bd
JS
269 echo resolved > file1 &&
270 git add file1 &&
271 git rebase --continue > output &&
272 grep "^ file1 | 2 +-$" output
273'
274
6368f3f8
JS
275test_expect_success 'multi-squash only fires up editor once' '
276 base=$(git rev-parse HEAD~4) &&
277 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
959c0d06 278 EXPECT_HEADER_COUNT=4 \
6368f3f8
JS
279 git rebase -i $base &&
280 test $base = $(git rev-parse HEAD^) &&
281 test 1 = $(git show | grep ONCE | wc -l)
282'
283
a25eb139 284test_expect_success 'multi-fixup does not fire up editor' '
0205e72f
MH
285 git checkout -b multi-fixup E &&
286 base=$(git rev-parse HEAD~4) &&
a25eb139 287 FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
0205e72f
MH
288 git rebase -i $base &&
289 test $base = $(git rev-parse HEAD^) &&
a25eb139 290 test 0 = $(git show | grep NEVER | wc -l) &&
0205e72f
MH
291 git checkout to-be-rebased &&
292 git branch -D multi-fixup
293'
294
6bdcd0d2
MH
295test_expect_success 'commit message used after conflict' '
296 git checkout -b conflict-fixup conflict-branch &&
297 base=$(git rev-parse HEAD~4) &&
298 (
299 FAKE_LINES="1 fixup 3 fixup 4" &&
300 export FAKE_LINES &&
301 test_must_fail git rebase -i $base
302 ) &&
303 echo three > conflict &&
304 git add conflict &&
305 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
306 git rebase --continue &&
307 test $base = $(git rev-parse HEAD^) &&
308 test 1 = $(git show | grep ONCE | wc -l) &&
309 git checkout to-be-rebased &&
310 git branch -D conflict-fixup
311'
312
313test_expect_success 'commit message retained after conflict' '
314 git checkout -b conflict-squash conflict-branch &&
315 base=$(git rev-parse HEAD~4) &&
316 (
317 FAKE_LINES="1 fixup 3 squash 4" &&
318 export FAKE_LINES &&
319 test_must_fail git rebase -i $base
320 ) &&
321 echo three > conflict &&
322 git add conflict &&
323 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
324 git rebase --continue &&
325 test $base = $(git rev-parse HEAD^) &&
326 test 2 = $(git show | grep TWICE | wc -l) &&
327 git checkout to-be-rebased &&
328 git branch -D conflict-squash
329'
330
0205e72f
MH
331cat > expect-squash-fixup << EOF
332B
333
334D
335
336ONCE
337EOF
338
339test_expect_success 'squash and fixup generate correct log messages' '
340 git checkout -b squash-fixup E &&
341 base=$(git rev-parse HEAD~4) &&
342 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
959c0d06 343 EXPECT_HEADER_COUNT=4 \
0205e72f
MH
344 git rebase -i $base &&
345 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
346 test_cmp expect-squash-fixup actual-squash-fixup &&
347 git checkout to-be-rebased &&
348 git branch -D squash-fixup
349'
350
234b3dae
MH
351test_expect_success 'squash ignores comments' '
352 git checkout -b skip-comments E &&
353 base=$(git rev-parse HEAD~4) &&
354 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
355 EXPECT_HEADER_COUNT=4 \
356 git rebase -i $base &&
357 test $base = $(git rev-parse HEAD^) &&
358 test 1 = $(git show | grep ONCE | wc -l) &&
359 git checkout to-be-rebased &&
360 git branch -D skip-comments
361'
362
363test_expect_success 'squash ignores blank lines' '
364 git checkout -b skip-blank-lines E &&
365 base=$(git rev-parse HEAD~4) &&
366 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
367 EXPECT_HEADER_COUNT=4 \
368 git rebase -i $base &&
369 test $base = $(git rev-parse HEAD^) &&
370 test 1 = $(git show | grep ONCE | wc -l) &&
371 git checkout to-be-rebased &&
372 git branch -D skip-blank-lines
373'
374
fb47cfbd 375test_expect_success 'squash works as expected' '
6c4c44c4 376 git checkout -b squash-works no-conflict-branch &&
fb47cfbd 377 one=$(git rev-parse HEAD~3) &&
5065ed29 378 FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
959c0d06 379 git rebase -i HEAD~3 &&
fb47cfbd
JS
380 test $one = $(git rev-parse HEAD~2)
381'
382
383test_expect_success 'interrupted squash works as expected' '
6c4c44c4 384 git checkout -b interrupted-squash conflict-branch &&
fb47cfbd 385 one=$(git rev-parse HEAD~3) &&
ab736792
SB
386 (
387 FAKE_LINES="1 squash 3 2" &&
388 export FAKE_LINES &&
389 test_must_fail git rebase -i HEAD~3
390 ) &&
fb47cfbd
JS
391 (echo one; echo two; echo four) > conflict &&
392 git add conflict &&
ab736792 393 test_must_fail git rebase --continue &&
fb47cfbd
JS
394 echo resolved > conflict &&
395 git add conflict &&
396 git rebase --continue &&
397 test $one = $(git rev-parse HEAD~2)
398'
399
1d25c8cf 400test_expect_success 'interrupted squash works as expected (case 2)' '
6c4c44c4 401 git checkout -b interrupted-squash2 conflict-branch &&
1d25c8cf 402 one=$(git rev-parse HEAD~3) &&
ab736792
SB
403 (
404 FAKE_LINES="3 squash 1 2" &&
405 export FAKE_LINES &&
406 test_must_fail git rebase -i HEAD~3
407 ) &&
1d25c8cf
JS
408 (echo one; echo four) > conflict &&
409 git add conflict &&
ab736792 410 test_must_fail git rebase --continue &&
1d25c8cf
JS
411 (echo one; echo two; echo four) > conflict &&
412 git add conflict &&
ab736792 413 test_must_fail git rebase --continue &&
1d25c8cf
JS
414 echo resolved > conflict &&
415 git add conflict &&
416 git rebase --continue &&
417 test $one = $(git rev-parse HEAD~2)
418'
419
96ffe892
JS
420test_expect_success 'ignore patch if in upstream' '
421 HEAD=$(git rev-parse HEAD) &&
422 git checkout -b has-cherry-picked HEAD^ &&
423 echo unrelated > file7 &&
424 git add file7 &&
425 test_tick &&
426 git commit -m "unrelated change" &&
427 git cherry-pick $HEAD &&
428 EXPECT_COUNT=1 git rebase -i $HEAD &&
429 test $HEAD = $(git rev-parse HEAD^)
430'
431
be6ff208
JS
432test_expect_success '--continue tries to commit, even for "edit"' '
433 parent=$(git rev-parse HEAD^) &&
434 test_tick &&
435 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
436 echo edited > file7 &&
437 git add file7 &&
438 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
439 test edited = $(git show HEAD:file7) &&
440 git show HEAD | grep chouette &&
441 test $parent = $(git rev-parse HEAD^)
442'
443
dc7f55cb
SB
444test_expect_success 'aborted --continue does not squash commits after "edit"' '
445 old=$(git rev-parse HEAD) &&
446 test_tick &&
447 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
448 echo "edited again" > file7 &&
449 git add file7 &&
450 (
451 FAKE_COMMIT_MESSAGE=" " &&
452 export FAKE_COMMIT_MESSAGE &&
453 test_must_fail git rebase --continue
454 ) &&
455 test $old = $(git rev-parse HEAD) &&
456 git rebase --abort
457'
458
f8aa1b69
SB
459test_expect_success 'auto-amend only edited commits after "edit"' '
460 test_tick &&
461 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
462 echo "edited again" > file7 &&
463 git add file7 &&
464 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
465 echo "and again" > file7 &&
466 git add file7 &&
467 test_tick &&
468 (
469 FAKE_COMMIT_MESSAGE="and again" &&
470 export FAKE_COMMIT_MESSAGE &&
471 test_must_fail git rebase --continue
472 ) &&
473 git rebase --abort
474'
475
73697a0b
JS
476test_expect_success 'rebase a detached HEAD' '
477 grandparent=$(git rev-parse HEAD~2) &&
478 git checkout $(git rev-parse HEAD) &&
479 test_tick &&
480 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
481 test $grandparent = $(git rev-parse HEAD~2)
482'
483
752527f5
JS
484test_expect_success 'rebase a commit violating pre-commit' '
485
486 mkdir -p .git/hooks &&
487 PRE_COMMIT=.git/hooks/pre-commit &&
488 echo "#!/bin/sh" > $PRE_COMMIT &&
489 echo "test -z \"\$(git diff --cached --check)\"" >> $PRE_COMMIT &&
490 chmod a+x $PRE_COMMIT &&
491 echo "monde! " >> file1 &&
492 test_tick &&
ab736792 493 test_must_fail git commit -m doesnt-verify file1 &&
752527f5
JS
494 git commit -m doesnt-verify --no-verify file1 &&
495 test_tick &&
496 FAKE_LINES=2 git rebase -i HEAD~2
497
498'
499
077b725f
JH
500test_expect_success 'rebase with a file named HEAD in worktree' '
501
502 rm -fr .git/hooks &&
503 git reset --hard &&
504 git checkout -b branch3 A &&
505
506 (
507 GIT_AUTHOR_NAME="Squashed Away" &&
508 export GIT_AUTHOR_NAME &&
509 >HEAD &&
510 git add HEAD &&
511 git commit -m "Add head" &&
512 >BODY &&
513 git add BODY &&
514 git commit -m "Add body"
515 ) &&
516
517 FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
518 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
519
520'
521
ff74126c
JS
522test_expect_success 'do "noop" when there is nothing to cherry-pick' '
523
524 git checkout -b branch4 HEAD &&
525 GIT_EDITOR=: git commit --amend \
526 --author="Somebody else <somebody@else.com>"
527 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
528 git rebase -i branch3 &&
529 test $(git rev-parse branch3) = $(git rev-parse branch4)
530
531'
532
96747696
JH
533test_expect_success 'submodule rebase setup' '
534 git checkout A &&
535 mkdir sub &&
536 (
537 cd sub && git init && >elif &&
538 git add elif && git commit -m "submodule initial"
539 ) &&
540 echo 1 >file1 &&
541 git add file1 sub
542 test_tick &&
543 git commit -m "One" &&
544 echo 2 >file1 &&
545 test_tick &&
546 git commit -a -m "Two" &&
547 (
548 cd sub && echo 3 >elif &&
549 git commit -a -m "submodule second"
550 ) &&
551 test_tick &&
552 git commit -a -m "Three changes submodule"
553'
554
94c88ede 555test_expect_success 'submodule rebase -i' '
96747696
JH
556 FAKE_LINES="1 squash 2 3" git rebase -i A
557'
558
0e757e30
JS
559test_expect_success 'avoid unnecessary reset' '
560 git checkout master &&
561 test-chmtime =123456789 file3 &&
562 git update-index --refresh &&
563 HEAD=$(git rev-parse HEAD) &&
564 git rebase -i HEAD~4 &&
565 test $HEAD = $(git rev-parse HEAD) &&
566 MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
567 test 123456789 = $MTIME
568'
569
6741aa6c
BG
570test_expect_success 'reword' '
571 git checkout -b reword-branch master &&
572 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
573 git show HEAD | grep "E changed" &&
574 test $(git rev-parse master) != $(git rev-parse HEAD) &&
575 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
576 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
577 git show HEAD^ | grep "D changed" &&
578 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
579 git show HEAD~3 | grep "B changed" &&
580 FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
581 git show HEAD~2 | grep "C changed"
582'
583
eb2151bb
TR
584test_expect_success 'rebase -i can copy notes' '
585 git config notes.rewrite.rebase true &&
586 git config notes.rewriteRef "refs/notes/*" &&
587 test_commit n1 &&
588 test_commit n2 &&
589 test_commit n3 &&
590 git notes add -m"a note" n3 &&
591 git rebase --onto n1 n2 &&
592 test "a note" = "$(git notes show HEAD)"
593'
594
595cat >expect <<EOF
596an earlier note
597a note
598EOF
599
600test_expect_success 'rebase -i can copy notes over a fixup' '
601 git reset --hard n3 &&
602 git notes add -m"an earlier note" n2 &&
603 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
604 git notes show > output &&
605 test_cmp expect output
606'
607
2ec33cdd
DO
608test_expect_success 'rebase while detaching HEAD' '
609 git symbolic-ref HEAD &&
610 grandparent=$(git rev-parse HEAD~2) &&
611 test_tick &&
612 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
613 test $grandparent = $(git rev-parse HEAD~2) &&
614 test_must_fail git symbolic-ref HEAD
615'
616
b4995494
MB
617test_tick # Ensure that the rebased commits get a different timestamp.
618test_expect_success 'always cherry-pick with --no-ff' '
619 git checkout no-ff-branch &&
620 git tag original-no-ff-branch &&
621 git rebase -i --no-ff A &&
622 touch empty &&
623 for p in 0 1 2
624 do
625 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
626 git diff HEAD~$p original-no-ff-branch~$p > out &&
627 test_cmp empty out
628 done &&
629 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
630 git diff HEAD~3 original-no-ff-branch~3 > out &&
631 test_cmp empty out
632'
633
57f2b6b2
JH
634test_expect_success 'set up commits with funny messages' '
635 git checkout -b funny A &&
636 echo >>file1 &&
637 test_tick &&
638 git commit -a -m "end with slash\\" &&
639 echo >>file1 &&
640 test_tick &&
641 git commit -a -m "another commit"
642'
643
644test_expect_success 'rebase-i history with funny messages' '
645 git rev-list A..funny >expect &&
646 test_tick &&
647 FAKE_LINES="1 2" git rebase -i A &&
648 git rev-list A.. >actual &&
649 test_cmp expect actual
650'
651
1b1dce4b 652test_done