]>
Commit | Line | Data |
---|---|---|
1b1dce4b JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Johannes E. Schindelin | |
4 | # | |
5 | ||
6 | test_description='git rebase interactive | |
7 | ||
8 | This test runs git rebase "interactively", by faking an edit, and verifies | |
9 | that the result still makes sense. | |
99b028e5 JN |
10 | |
11 | Initial 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 | 32 | test_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 |
38 | set_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 | 43 | test_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 | 75 | SHELL= |
5cd3e107 | 76 | export SHELL |
cd035b1c MM |
77 | |
78 | test_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 | ||
99 | test_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 | ||
109 | test_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 | 121 | test_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 |
128 | test_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 |
138 | test_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 |
146 | test_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 |
156 | test_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 |
160 | test_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 | ||
166 | cat > expect << EOF | |
167 | diff --git a/file1 b/file1 | |
163f3925 | 168 | index f70f10e..fd79235 100644 |
1b1dce4b JS |
169 | --- a/file1 |
170 | +++ b/file1 | |
163f3925 MH |
171 | @@ -1 +1 @@ |
172 | -A | |
173 | +G | |
1b1dce4b JS |
174 | EOF |
175 | ||
176 | cat > expect2 << EOF | |
606475f3 | 177 | <<<<<<< HEAD |
163f3925 | 178 | D |
1b1dce4b | 179 | ======= |
163f3925 | 180 | G |
b4995494 | 181 | >>>>>>> 5d18e54... G |
1b1dce4b JS |
182 | EOF |
183 | ||
184 | test_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 | ||
196 | test_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 |
203 | test_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 |
214 | test_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 | ||
224 | test_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 | ||
236 | test_expect_success 'retain authorship when squashing' ' | |
81ab1cb4 | 237 | git show HEAD | grep "^Author: Twerp Snog" |
1b1dce4b JS |
238 | ' |
239 | ||
34454e85 JS |
240 | test_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 | 249 | test_expect_failure 'exchange two commits with -p' ' |
27ccd8d1 | 250 | git checkout H && |
cddb42d2 JN |
251 | FAKE_LINES="2 1" git rebase -i -p HEAD~2 && |
252 | test H = $(git cat-file commit HEAD^ | sed -ne \$p) && | |
253 | test G = $(git cat-file commit HEAD | sed -ne \$p) | |
254 | ' | |
255 | ||
f09c9b8c JS |
256 | test_expect_success 'preserve merges with -p' ' |
257 | git checkout -b to-be-preserved master^ && | |
258 | : > unrelated-file && | |
259 | git add unrelated-file && | |
260 | test_tick && | |
261 | git commit -m "unrelated" && | |
5352a82b | 262 | git checkout -b another-branch master && |
f09c9b8c JS |
263 | echo B > file1 && |
264 | test_tick && | |
265 | git commit -m J file1 && | |
266 | test_tick && | |
267 | git merge to-be-preserved && | |
268 | echo C > file1 && | |
269 | test_tick && | |
270 | git commit -m K file1 && | |
5352a82b SB |
271 | echo D > file1 && |
272 | test_tick && | |
273 | git commit -m L1 file1 && | |
274 | git checkout HEAD^ && | |
275 | echo 1 > unrelated-file && | |
276 | test_tick && | |
277 | git commit -m L2 unrelated-file && | |
278 | test_tick && | |
279 | git merge another-branch && | |
280 | echo E > file1 && | |
281 | test_tick && | |
282 | git commit -m M file1 && | |
283 | git checkout -b to-be-rebased && | |
18640d99 | 284 | test_tick && |
f09c9b8c | 285 | git rebase -i -p --onto branch1 master && |
71d9451e TR |
286 | git update-index --refresh && |
287 | git diff-files --quiet && | |
288 | git diff-index --quiet --cached HEAD -- && | |
5352a82b SB |
289 | test $(git rev-parse HEAD~6) = $(git rev-parse branch1) && |
290 | test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) && | |
291 | test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) && | |
292 | test $(git show HEAD~5:file1) = B && | |
293 | test $(git show HEAD~3:file1) = C && | |
294 | test $(git show HEAD:file1) = E && | |
295 | test $(git show HEAD:unrelated-file) = 1 | |
f09c9b8c JS |
296 | ' |
297 | ||
a96dc01e | 298 | test_expect_success 'edit ancestor with -p' ' |
12bf8283 | 299 | FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 && |
a96dc01e TR |
300 | echo 2 > unrelated-file && |
301 | test_tick && | |
302 | git commit -m L2-modified --amend unrelated-file && | |
303 | git rebase --continue && | |
304 | git update-index --refresh && | |
305 | git diff-files --quiet && | |
306 | git diff-index --quiet --cached HEAD -- && | |
307 | test $(git show HEAD:unrelated-file) = 2 | |
308 | ' | |
309 | ||
18640d99 JS |
310 | test_expect_success '--continue tries to commit' ' |
311 | test_tick && | |
ab736792 | 312 | test_must_fail git rebase -i --onto new-branch1 HEAD^ && |
18640d99 JS |
313 | echo resolved > file1 && |
314 | git add file1 && | |
315 | FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue && | |
316 | test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) && | |
317 | git show HEAD | grep chouette | |
318 | ' | |
319 | ||
8e4a91bd | 320 | test_expect_success 'verbose flag is heeded, even after --continue' ' |
53f2ffa8 | 321 | git reset --hard master@{1} && |
8e4a91bd | 322 | test_tick && |
ab736792 | 323 | test_must_fail git rebase -v -i --onto new-branch1 HEAD^ && |
8e4a91bd JS |
324 | echo resolved > file1 && |
325 | git add file1 && | |
326 | git rebase --continue > output && | |
dc801e71 | 327 | grep "^ file1 | 2 +-$" output |
8e4a91bd JS |
328 | ' |
329 | ||
6368f3f8 JS |
330 | test_expect_success 'multi-squash only fires up editor once' ' |
331 | base=$(git rev-parse HEAD~4) && | |
332 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \ | |
959c0d06 | 333 | EXPECT_HEADER_COUNT=4 \ |
6368f3f8 JS |
334 | git rebase -i $base && |
335 | test $base = $(git rev-parse HEAD^) && | |
336 | test 1 = $(git show | grep ONCE | wc -l) | |
337 | ' | |
338 | ||
a25eb139 | 339 | test_expect_success 'multi-fixup does not fire up editor' ' |
0205e72f MH |
340 | git checkout -b multi-fixup E && |
341 | base=$(git rev-parse HEAD~4) && | |
a25eb139 | 342 | FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ |
0205e72f MH |
343 | git rebase -i $base && |
344 | test $base = $(git rev-parse HEAD^) && | |
a25eb139 | 345 | test 0 = $(git show | grep NEVER | wc -l) && |
0205e72f MH |
346 | git checkout to-be-rebased && |
347 | git branch -D multi-fixup | |
348 | ' | |
349 | ||
6bdcd0d2 MH |
350 | test_expect_success 'commit message used after conflict' ' |
351 | git checkout -b conflict-fixup conflict-branch && | |
352 | base=$(git rev-parse HEAD~4) && | |
353 | ( | |
354 | FAKE_LINES="1 fixup 3 fixup 4" && | |
355 | export FAKE_LINES && | |
356 | test_must_fail git rebase -i $base | |
357 | ) && | |
358 | echo three > conflict && | |
359 | git add conflict && | |
360 | FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \ | |
361 | git rebase --continue && | |
362 | test $base = $(git rev-parse HEAD^) && | |
363 | test 1 = $(git show | grep ONCE | wc -l) && | |
364 | git checkout to-be-rebased && | |
365 | git branch -D conflict-fixup | |
366 | ' | |
367 | ||
368 | test_expect_success 'commit message retained after conflict' ' | |
369 | git checkout -b conflict-squash conflict-branch && | |
370 | base=$(git rev-parse HEAD~4) && | |
371 | ( | |
372 | FAKE_LINES="1 fixup 3 squash 4" && | |
373 | export FAKE_LINES && | |
374 | test_must_fail git rebase -i $base | |
375 | ) && | |
376 | echo three > conflict && | |
377 | git add conflict && | |
378 | FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \ | |
379 | git rebase --continue && | |
380 | test $base = $(git rev-parse HEAD^) && | |
381 | test 2 = $(git show | grep TWICE | wc -l) && | |
382 | git checkout to-be-rebased && | |
383 | git branch -D conflict-squash | |
384 | ' | |
385 | ||
0205e72f MH |
386 | cat > expect-squash-fixup << EOF |
387 | B | |
388 | ||
389 | D | |
390 | ||
391 | ONCE | |
392 | EOF | |
393 | ||
394 | test_expect_success 'squash and fixup generate correct log messages' ' | |
395 | git checkout -b squash-fixup E && | |
396 | base=$(git rev-parse HEAD~4) && | |
397 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \ | |
959c0d06 | 398 | EXPECT_HEADER_COUNT=4 \ |
0205e72f MH |
399 | git rebase -i $base && |
400 | git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup && | |
401 | test_cmp expect-squash-fixup actual-squash-fixup && | |
402 | git checkout to-be-rebased && | |
403 | git branch -D squash-fixup | |
404 | ' | |
405 | ||
234b3dae MH |
406 | test_expect_success 'squash ignores comments' ' |
407 | git checkout -b skip-comments E && | |
408 | base=$(git rev-parse HEAD~4) && | |
409 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \ | |
410 | EXPECT_HEADER_COUNT=4 \ | |
411 | git rebase -i $base && | |
412 | test $base = $(git rev-parse HEAD^) && | |
413 | test 1 = $(git show | grep ONCE | wc -l) && | |
414 | git checkout to-be-rebased && | |
415 | git branch -D skip-comments | |
416 | ' | |
417 | ||
418 | test_expect_success 'squash ignores blank lines' ' | |
419 | git checkout -b skip-blank-lines E && | |
420 | base=$(git rev-parse HEAD~4) && | |
421 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \ | |
422 | EXPECT_HEADER_COUNT=4 \ | |
423 | git rebase -i $base && | |
424 | test $base = $(git rev-parse HEAD^) && | |
425 | test 1 = $(git show | grep ONCE | wc -l) && | |
426 | git checkout to-be-rebased && | |
427 | git branch -D skip-blank-lines | |
428 | ' | |
429 | ||
fb47cfbd | 430 | test_expect_success 'squash works as expected' ' |
6c4c44c4 | 431 | git checkout -b squash-works no-conflict-branch && |
fb47cfbd | 432 | one=$(git rev-parse HEAD~3) && |
5065ed29 | 433 | FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \ |
959c0d06 | 434 | git rebase -i HEAD~3 && |
fb47cfbd JS |
435 | test $one = $(git rev-parse HEAD~2) |
436 | ' | |
437 | ||
438 | test_expect_success 'interrupted squash works as expected' ' | |
6c4c44c4 | 439 | git checkout -b interrupted-squash conflict-branch && |
fb47cfbd | 440 | one=$(git rev-parse HEAD~3) && |
ab736792 SB |
441 | ( |
442 | FAKE_LINES="1 squash 3 2" && | |
443 | export FAKE_LINES && | |
444 | test_must_fail git rebase -i HEAD~3 | |
445 | ) && | |
fb47cfbd JS |
446 | (echo one; echo two; echo four) > conflict && |
447 | git add conflict && | |
ab736792 | 448 | test_must_fail git rebase --continue && |
fb47cfbd JS |
449 | echo resolved > conflict && |
450 | git add conflict && | |
451 | git rebase --continue && | |
452 | test $one = $(git rev-parse HEAD~2) | |
453 | ' | |
454 | ||
1d25c8cf | 455 | test_expect_success 'interrupted squash works as expected (case 2)' ' |
6c4c44c4 | 456 | git checkout -b interrupted-squash2 conflict-branch && |
1d25c8cf | 457 | one=$(git rev-parse HEAD~3) && |
ab736792 SB |
458 | ( |
459 | FAKE_LINES="3 squash 1 2" && | |
460 | export FAKE_LINES && | |
461 | test_must_fail git rebase -i HEAD~3 | |
462 | ) && | |
1d25c8cf JS |
463 | (echo one; echo four) > conflict && |
464 | git add conflict && | |
ab736792 | 465 | test_must_fail git rebase --continue && |
1d25c8cf JS |
466 | (echo one; echo two; echo four) > conflict && |
467 | git add conflict && | |
ab736792 | 468 | test_must_fail git rebase --continue && |
1d25c8cf JS |
469 | echo resolved > conflict && |
470 | git add conflict && | |
471 | git rebase --continue && | |
472 | test $one = $(git rev-parse HEAD~2) | |
473 | ' | |
474 | ||
96ffe892 JS |
475 | test_expect_success 'ignore patch if in upstream' ' |
476 | HEAD=$(git rev-parse HEAD) && | |
477 | git checkout -b has-cherry-picked HEAD^ && | |
478 | echo unrelated > file7 && | |
479 | git add file7 && | |
480 | test_tick && | |
481 | git commit -m "unrelated change" && | |
482 | git cherry-pick $HEAD && | |
483 | EXPECT_COUNT=1 git rebase -i $HEAD && | |
484 | test $HEAD = $(git rev-parse HEAD^) | |
485 | ' | |
486 | ||
be6ff208 JS |
487 | test_expect_success '--continue tries to commit, even for "edit"' ' |
488 | parent=$(git rev-parse HEAD^) && | |
489 | test_tick && | |
490 | FAKE_LINES="edit 1" git rebase -i HEAD^ && | |
491 | echo edited > file7 && | |
492 | git add file7 && | |
493 | FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue && | |
494 | test edited = $(git show HEAD:file7) && | |
495 | git show HEAD | grep chouette && | |
496 | test $parent = $(git rev-parse HEAD^) | |
497 | ' | |
498 | ||
dc7f55cb SB |
499 | test_expect_success 'aborted --continue does not squash commits after "edit"' ' |
500 | old=$(git rev-parse HEAD) && | |
501 | test_tick && | |
502 | FAKE_LINES="edit 1" git rebase -i HEAD^ && | |
503 | echo "edited again" > file7 && | |
504 | git add file7 && | |
505 | ( | |
506 | FAKE_COMMIT_MESSAGE=" " && | |
507 | export FAKE_COMMIT_MESSAGE && | |
508 | test_must_fail git rebase --continue | |
509 | ) && | |
510 | test $old = $(git rev-parse HEAD) && | |
511 | git rebase --abort | |
512 | ' | |
513 | ||
f8aa1b69 SB |
514 | test_expect_success 'auto-amend only edited commits after "edit"' ' |
515 | test_tick && | |
516 | FAKE_LINES="edit 1" git rebase -i HEAD^ && | |
517 | echo "edited again" > file7 && | |
518 | git add file7 && | |
519 | FAKE_COMMIT_MESSAGE="edited file7 again" git commit && | |
520 | echo "and again" > file7 && | |
521 | git add file7 && | |
522 | test_tick && | |
523 | ( | |
524 | FAKE_COMMIT_MESSAGE="and again" && | |
525 | export FAKE_COMMIT_MESSAGE && | |
526 | test_must_fail git rebase --continue | |
527 | ) && | |
528 | git rebase --abort | |
529 | ' | |
530 | ||
ffaaed88 MM |
531 | test_expect_success 'clean error after failed "exec"' ' |
532 | test_tick && | |
533 | test_when_finished "git rebase --abort || :" && | |
534 | ( | |
535 | FAKE_LINES="1 exec_false" && | |
536 | export FAKE_LINES && | |
537 | test_must_fail git rebase -i HEAD^ | |
538 | ) && | |
539 | echo "edited again" > file7 && | |
540 | git add file7 && | |
541 | test_must_fail git rebase --continue 2>error && | |
542 | grep "You have staged changes in your working tree." error | |
543 | ' | |
544 | ||
73697a0b JS |
545 | test_expect_success 'rebase a detached HEAD' ' |
546 | grandparent=$(git rev-parse HEAD~2) && | |
547 | git checkout $(git rev-parse HEAD) && | |
548 | test_tick && | |
549 | FAKE_LINES="2 1" git rebase -i HEAD~2 && | |
550 | test $grandparent = $(git rev-parse HEAD~2) | |
551 | ' | |
552 | ||
752527f5 JS |
553 | test_expect_success 'rebase a commit violating pre-commit' ' |
554 | ||
555 | mkdir -p .git/hooks && | |
556 | PRE_COMMIT=.git/hooks/pre-commit && | |
557 | echo "#!/bin/sh" > $PRE_COMMIT && | |
558 | echo "test -z \"\$(git diff --cached --check)\"" >> $PRE_COMMIT && | |
559 | chmod a+x $PRE_COMMIT && | |
560 | echo "monde! " >> file1 && | |
561 | test_tick && | |
ab736792 | 562 | test_must_fail git commit -m doesnt-verify file1 && |
752527f5 JS |
563 | git commit -m doesnt-verify --no-verify file1 && |
564 | test_tick && | |
565 | FAKE_LINES=2 git rebase -i HEAD~2 | |
566 | ||
567 | ' | |
568 | ||
077b725f JH |
569 | test_expect_success 'rebase with a file named HEAD in worktree' ' |
570 | ||
571 | rm -fr .git/hooks && | |
572 | git reset --hard && | |
573 | git checkout -b branch3 A && | |
574 | ||
575 | ( | |
576 | GIT_AUTHOR_NAME="Squashed Away" && | |
577 | export GIT_AUTHOR_NAME && | |
578 | >HEAD && | |
579 | git add HEAD && | |
580 | git commit -m "Add head" && | |
581 | >BODY && | |
582 | git add BODY && | |
583 | git commit -m "Add body" | |
584 | ) && | |
585 | ||
586 | FAKE_LINES="1 squash 2" git rebase -i to-be-rebased && | |
587 | test "$(git show -s --pretty=format:%an)" = "Squashed Away" | |
588 | ||
589 | ' | |
590 | ||
ff74126c JS |
591 | test_expect_success 'do "noop" when there is nothing to cherry-pick' ' |
592 | ||
593 | git checkout -b branch4 HEAD && | |
594 | GIT_EDITOR=: git commit --amend \ | |
2dec68cf | 595 | --author="Somebody else <somebody@else.com>" && |
ff74126c JS |
596 | test $(git rev-parse branch3) != $(git rev-parse branch4) && |
597 | git rebase -i branch3 && | |
598 | test $(git rev-parse branch3) = $(git rev-parse branch4) | |
599 | ||
600 | ' | |
601 | ||
96747696 JH |
602 | test_expect_success 'submodule rebase setup' ' |
603 | git checkout A && | |
604 | mkdir sub && | |
605 | ( | |
606 | cd sub && git init && >elif && | |
607 | git add elif && git commit -m "submodule initial" | |
608 | ) && | |
609 | echo 1 >file1 && | |
2dec68cf | 610 | git add file1 sub && |
96747696 JH |
611 | test_tick && |
612 | git commit -m "One" && | |
613 | echo 2 >file1 && | |
614 | test_tick && | |
615 | git commit -a -m "Two" && | |
616 | ( | |
617 | cd sub && echo 3 >elif && | |
618 | git commit -a -m "submodule second" | |
619 | ) && | |
620 | test_tick && | |
621 | git commit -a -m "Three changes submodule" | |
622 | ' | |
623 | ||
94c88ede | 624 | test_expect_success 'submodule rebase -i' ' |
96747696 JH |
625 | FAKE_LINES="1 squash 2 3" git rebase -i A |
626 | ' | |
627 | ||
a6754cda JK |
628 | test_expect_success 'submodule conflict setup' ' |
629 | git tag submodule-base && | |
630 | git checkout HEAD^ && | |
631 | ( | |
632 | cd sub && git checkout HEAD^ && echo 4 >elif && | |
633 | git add elif && git commit -m "submodule conflict" | |
634 | ) && | |
635 | git add sub && | |
636 | test_tick && | |
637 | git commit -m "Conflict in submodule" && | |
638 | git tag submodule-topic | |
639 | ' | |
640 | ||
641 | test_expect_success 'rebase -i continue with only submodule staged' ' | |
642 | test_must_fail git rebase -i submodule-base && | |
643 | git add sub && | |
644 | git rebase --continue && | |
645 | test $(git rev-parse submodule-base) != $(git rev-parse HEAD) | |
646 | ' | |
647 | ||
648 | test_expect_success 'rebase -i continue with unstaged submodule' ' | |
649 | git checkout submodule-topic && | |
650 | git reset --hard && | |
651 | test_must_fail git rebase -i submodule-base && | |
652 | git reset && | |
653 | git rebase --continue && | |
654 | test $(git rev-parse submodule-base) = $(git rev-parse HEAD) | |
655 | ' | |
656 | ||
0e757e30 JS |
657 | test_expect_success 'avoid unnecessary reset' ' |
658 | git checkout master && | |
a6754cda | 659 | git reset --hard && |
0e757e30 JS |
660 | test-chmtime =123456789 file3 && |
661 | git update-index --refresh && | |
662 | HEAD=$(git rev-parse HEAD) && | |
663 | git rebase -i HEAD~4 && | |
664 | test $HEAD = $(git rev-parse HEAD) && | |
665 | MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') && | |
666 | test 123456789 = $MTIME | |
667 | ' | |
668 | ||
6741aa6c BG |
669 | test_expect_success 'reword' ' |
670 | git checkout -b reword-branch master && | |
671 | FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A && | |
672 | git show HEAD | grep "E changed" && | |
673 | test $(git rev-parse master) != $(git rev-parse HEAD) && | |
674 | test $(git rev-parse master^) = $(git rev-parse HEAD^) && | |
675 | FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A && | |
676 | git show HEAD^ | grep "D changed" && | |
677 | FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A && | |
678 | git show HEAD~3 | grep "B changed" && | |
679 | FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A && | |
680 | git show HEAD~2 | grep "C changed" | |
681 | ' | |
682 | ||
eb2151bb TR |
683 | test_expect_success 'rebase -i can copy notes' ' |
684 | git config notes.rewrite.rebase true && | |
685 | git config notes.rewriteRef "refs/notes/*" && | |
686 | test_commit n1 && | |
687 | test_commit n2 && | |
688 | test_commit n3 && | |
689 | git notes add -m"a note" n3 && | |
690 | git rebase --onto n1 n2 && | |
691 | test "a note" = "$(git notes show HEAD)" | |
692 | ' | |
693 | ||
694 | cat >expect <<EOF | |
695 | an earlier note | |
d4990c4b | 696 | |
eb2151bb TR |
697 | a note |
698 | EOF | |
699 | ||
700 | test_expect_success 'rebase -i can copy notes over a fixup' ' | |
701 | git reset --hard n3 && | |
702 | git notes add -m"an earlier note" n2 && | |
703 | GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 && | |
704 | git notes show > output && | |
705 | test_cmp expect output | |
706 | ' | |
707 | ||
2ec33cdd DO |
708 | test_expect_success 'rebase while detaching HEAD' ' |
709 | git symbolic-ref HEAD && | |
710 | grandparent=$(git rev-parse HEAD~2) && | |
711 | test_tick && | |
712 | FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 && | |
713 | test $grandparent = $(git rev-parse HEAD~2) && | |
714 | test_must_fail git symbolic-ref HEAD | |
715 | ' | |
716 | ||
b4995494 MB |
717 | test_tick # Ensure that the rebased commits get a different timestamp. |
718 | test_expect_success 'always cherry-pick with --no-ff' ' | |
719 | git checkout no-ff-branch && | |
720 | git tag original-no-ff-branch && | |
721 | git rebase -i --no-ff A && | |
722 | touch empty && | |
723 | for p in 0 1 2 | |
724 | do | |
725 | test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) && | |
726 | git diff HEAD~$p original-no-ff-branch~$p > out && | |
727 | test_cmp empty out | |
728 | done && | |
729 | test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) && | |
730 | git diff HEAD~3 original-no-ff-branch~3 > out && | |
731 | test_cmp empty out | |
732 | ' | |
733 | ||
57f2b6b2 JH |
734 | test_expect_success 'set up commits with funny messages' ' |
735 | git checkout -b funny A && | |
736 | echo >>file1 && | |
737 | test_tick && | |
738 | git commit -a -m "end with slash\\" && | |
739 | echo >>file1 && | |
740 | test_tick && | |
938791cd BC |
741 | git commit -a -m "something (\000) that looks like octal" && |
742 | echo >>file1 && | |
743 | test_tick && | |
744 | git commit -a -m "something (\n) that looks like a newline" && | |
745 | echo >>file1 && | |
746 | test_tick && | |
57f2b6b2 JH |
747 | git commit -a -m "another commit" |
748 | ' | |
749 | ||
750 | test_expect_success 'rebase-i history with funny messages' ' | |
751 | git rev-list A..funny >expect && | |
752 | test_tick && | |
938791cd | 753 | FAKE_LINES="1 2 3 4" git rebase -i A && |
57f2b6b2 JH |
754 | git rev-list A.. >actual && |
755 | test_cmp expect actual | |
756 | ' | |
757 | ||
c2145384 LK |
758 | |
759 | test_expect_success 'prepare for rebase -i --exec' ' | |
760 | git checkout master && | |
761 | git checkout -b execute && | |
762 | test_commit one_exec main.txt one_exec && | |
763 | test_commit two_exec main.txt two_exec && | |
764 | test_commit three_exec main.txt three_exec | |
765 | ' | |
766 | ||
767 | ||
768 | test_expect_success 'running "git rebase -i --exec git show HEAD"' ' | |
769 | git rebase -i --exec "git show HEAD" HEAD~2 >actual && | |
770 | ( | |
771 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
772 | export FAKE_LINES && | |
773 | git rebase -i HEAD~2 >expect | |
774 | ) && | |
775 | sed -e "1,9d" expect >expected && | |
776 | test_cmp expected actual | |
777 | ' | |
778 | ||
779 | ||
780 | test_expect_success 'running "git rebase --exec git show HEAD -i"' ' | |
781 | git reset --hard execute && | |
782 | git rebase --exec "git show HEAD" -i HEAD~2 >actual && | |
783 | ( | |
784 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
785 | export FAKE_LINES && | |
786 | git rebase -i HEAD~2 >expect | |
787 | ) && | |
788 | sed -e "1,9d" expect >expected && | |
789 | test_cmp expected actual | |
790 | ' | |
791 | ||
792 | ||
793 | test_expect_success 'running "git rebase -ix git show HEAD"' ' | |
794 | git reset --hard execute && | |
795 | git rebase -ix "git show HEAD" HEAD~2 >actual && | |
796 | ( | |
797 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
798 | export FAKE_LINES && | |
799 | git rebase -i HEAD~2 >expect | |
800 | ) && | |
801 | sed -e "1,9d" expect >expected && | |
802 | test_cmp expected actual | |
803 | ' | |
804 | ||
805 | ||
806 | test_expect_success 'rebase -ix with several <CMD>' ' | |
807 | git reset --hard execute && | |
808 | git rebase -ix "git show HEAD; pwd" HEAD~2 >actual && | |
809 | ( | |
810 | FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" && | |
811 | export FAKE_LINES && | |
812 | git rebase -i HEAD~2 >expect | |
813 | ) && | |
814 | sed -e "1,9d" expect >expected && | |
815 | test_cmp expected actual | |
816 | ' | |
817 | ||
818 | ||
819 | test_expect_success 'rebase -ix with several instances of --exec' ' | |
820 | git reset --hard execute && | |
821 | git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual && | |
822 | ( | |
823 | FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2 | |
824 | exec_git_show_HEAD exec_pwd" && | |
825 | export FAKE_LINES && | |
826 | git rebase -i HEAD~2 >expect | |
827 | ) && | |
828 | sed -e "1,11d" expect >expected && | |
829 | test_cmp expected actual | |
830 | ' | |
831 | ||
832 | ||
833 | test_expect_success 'rebase -ix with --autosquash' ' | |
834 | git reset --hard execute && | |
835 | git checkout -b autosquash && | |
836 | echo second >second.txt && | |
837 | git add second.txt && | |
838 | git commit -m "fixup! two_exec" && | |
839 | echo bis >bis.txt && | |
840 | git add bis.txt && | |
841 | git commit -m "fixup! two_exec" && | |
842 | ( | |
843 | git checkout -b autosquash_actual && | |
844 | git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual | |
845 | ) && | |
846 | git checkout autosquash && | |
847 | ( | |
848 | git checkout -b autosquash_expected && | |
849 | FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
850 | export FAKE_LINES && | |
851 | git rebase -i HEAD~4 >expect | |
852 | ) && | |
853 | sed -e "1,13d" expect >expected && | |
854 | test_cmp expected actual | |
855 | ' | |
856 | ||
857 | ||
858 | test_expect_success 'rebase --exec without -i shows error message' ' | |
859 | git reset --hard execute && | |
860 | test_must_fail git rebase --exec "git show HEAD" HEAD~2 2>actual && | |
465d6a00 | 861 | echo "The --exec option must be used with the --interactive option" >expected && |
c2145384 LK |
862 | test_i18ncmp expected actual |
863 | ' | |
864 | ||
865 | ||
866 | test_expect_success 'rebase -i --exec without <CMD>' ' | |
867 | git reset --hard execute && | |
868 | test_must_fail git rebase -i --exec 2>tmp && | |
869 | sed -e "1d" tmp >actual && | |
870 | test_must_fail git rebase -h >expected && | |
871 | test_cmp expected actual && | |
872 | git checkout master | |
873 | ' | |
874 | ||
b64b7feb CW |
875 | test_expect_success 'rebase -i --root re-order and drop commits' ' |
876 | git checkout E && | |
877 | FAKE_LINES="3 1 2 5" git rebase -i --root && | |
878 | test E = $(git cat-file commit HEAD | sed -ne \$p) && | |
879 | test B = $(git cat-file commit HEAD^ | sed -ne \$p) && | |
880 | test A = $(git cat-file commit HEAD^^ | sed -ne \$p) && | |
881 | test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) && | |
882 | test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ ) | |
883 | ' | |
884 | ||
885 | test_expect_success 'rebase -i --root retain root commit author and message' ' | |
886 | git checkout A && | |
887 | echo B >file7 && | |
888 | git add file7 && | |
889 | GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && | |
890 | FAKE_LINES="2" git rebase -i --root && | |
891 | git cat-file commit HEAD | grep -q "^author Twerp Snog" && | |
892 | git cat-file commit HEAD | grep -q "^different author$" | |
893 | ' | |
894 | ||
895 | test_expect_success 'rebase -i --root temporary sentinel commit' ' | |
896 | git checkout B && | |
994fd91d MG |
897 | ( |
898 | FAKE_LINES="2" && | |
899 | export FAKE_LINES && | |
900 | test_must_fail git rebase -i --root | |
901 | ) && | |
b64b7feb CW |
902 | git cat-file commit HEAD | grep "^tree 4b825dc642cb" && |
903 | git rebase --abort | |
904 | ' | |
905 | ||
2147f844 CW |
906 | test_expect_success 'rebase -i --root fixup root commit' ' |
907 | git checkout B && | |
908 | FAKE_LINES="1 fixup 2" git rebase -i --root && | |
909 | test A = $(git cat-file commit HEAD | sed -ne \$p) && | |
910 | test B = $(git show HEAD:file1) && | |
911 | test 0 = $(git cat-file commit HEAD | grep -c ^parent\ ) | |
912 | ' | |
913 | ||
1b1dce4b | 914 | test_done |