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