]>
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 JS |
31 | |
32 | set_fake_editor | |
33 | ||
b4995494 MB |
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 | 37 | test_expect_success 'setup' ' |
163f3925 MH |
38 | test_commit A file1 && |
39 | test_commit B file1 && | |
40 | test_commit C file2 && | |
41 | test_commit D file1 && | |
42 | test_commit E file3 && | |
1b1dce4b | 43 | git checkout -b branch1 A && |
163f3925 MH |
44 | test_commit F file4 && |
45 | test_commit G file1 && | |
46 | test_commit H file5 && | |
1b1dce4b | 47 | git checkout -b branch2 F && |
2dec68cf | 48 | test_commit I file6 && |
6c4c44c4 | 49 | git checkout -b conflict-branch A && |
391a825f JN |
50 | test_commit one conflict && |
51 | test_commit two conflict && | |
52 | test_commit three conflict && | |
53 | test_commit four conflict && | |
6c4c44c4 | 54 | git checkout -b no-conflict-branch A && |
391a825f JN |
55 | test_commit J fileJ && |
56 | test_commit K fileK && | |
57 | test_commit L fileL && | |
58 | test_commit M fileM && | |
b4995494 | 59 | git checkout -b no-ff-branch A && |
391a825f JN |
60 | test_commit N fileN && |
61 | test_commit O fileO && | |
62 | test_commit P fileP | |
1b1dce4b JS |
63 | ' |
64 | ||
cd035b1c MM |
65 | # "exec" commands are ran with the user shell by default, but this may |
66 | # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work | |
67 | # to create a file. Unseting SHELL avoids such non-portable behavior | |
5cd3e107 | 68 | # in tests. It must be exported for it to take effect where needed. |
cd035b1c | 69 | SHELL= |
5cd3e107 | 70 | export SHELL |
cd035b1c MM |
71 | |
72 | test_expect_success 'rebase -i with the exec command' ' | |
73 | git checkout master && | |
74 | ( | |
75 | FAKE_LINES="1 exec_>touch-one | |
76 | 2 exec_>touch-two exec_false exec_>touch-three | |
77 | 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" && | |
78 | export FAKE_LINES && | |
79 | test_must_fail git rebase -i A | |
80 | ) && | |
2caf20c5 MM |
81 | test_path_is_file touch-one && |
82 | test_path_is_file touch-two && | |
83 | test_path_is_missing touch-three " (should have stopped before)" && | |
5c947e2c | 84 | test_cmp_rev C HEAD && |
cd035b1c | 85 | git rebase --continue && |
2caf20c5 MM |
86 | test_path_is_file touch-three && |
87 | test_path_is_file "touch-file name with spaces" && | |
88 | test_path_is_file touch-after-semicolon && | |
5c947e2c | 89 | test_cmp_rev master HEAD && |
cd035b1c MM |
90 | rm -f touch-* |
91 | ' | |
92 | ||
93 | test_expect_success 'rebase -i with the exec command runs from tree root' ' | |
94 | git checkout master && | |
c2e0940b | 95 | mkdir subdir && (cd subdir && |
cd035b1c | 96 | FAKE_LINES="1 exec_>touch-subdir" \ |
c2e0940b JL |
97 | git rebase -i HEAD^ |
98 | ) && | |
2caf20c5 | 99 | test_path_is_file touch-subdir && |
cd035b1c MM |
100 | rm -fr subdir |
101 | ' | |
102 | ||
103 | test_expect_success 'rebase -i with the exec command checks tree cleanness' ' | |
104 | git checkout master && | |
105 | ( | |
106 | FAKE_LINES="exec_echo_foo_>file1 1" && | |
107 | export FAKE_LINES && | |
108 | test_must_fail git rebase -i HEAD^ | |
109 | ) && | |
5c947e2c | 110 | test_cmp_rev master^ HEAD && |
cd035b1c MM |
111 | git reset --hard && |
112 | git rebase --continue | |
113 | ' | |
114 | ||
ecfe1ea9 JS |
115 | test_expect_success 'rebase -i with exec of inexistent command' ' |
116 | git checkout master && | |
117 | test_when_finished "git rebase --abort" && | |
118 | ( | |
119 | FAKE_LINES="exec_this-command-does-not-exist 1" && | |
120 | export FAKE_LINES && | |
121 | test_must_fail git rebase -i HEAD^ >actual 2>&1 | |
122 | ) && | |
123 | ! grep "Maybe git-rebase is broken" actual | |
124 | ' | |
125 | ||
1b1dce4b | 126 | test_expect_success 'no changes are a nop' ' |
6c4c44c4 | 127 | git checkout branch2 && |
1b1dce4b | 128 | git rebase -i F && |
ab736792 | 129 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && |
1b1dce4b JS |
130 | test $(git rev-parse I) = $(git rev-parse HEAD) |
131 | ' | |
132 | ||
c9e65892 JS |
133 | test_expect_success 'test the [branch] option' ' |
134 | git checkout -b dead-end && | |
135 | git rm file6 && | |
136 | git commit -m "stop here" && | |
137 | git rebase -i F branch2 && | |
ab736792 SB |
138 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && |
139 | test $(git rev-parse I) = $(git rev-parse branch2) && | |
c9e65892 JS |
140 | test $(git rev-parse I) = $(git rev-parse HEAD) |
141 | ' | |
142 | ||
ab736792 SB |
143 | test_expect_success 'test --onto <branch>' ' |
144 | git checkout -b test-onto branch2 && | |
145 | git rebase -i --onto branch1 F && | |
146 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" && | |
147 | test $(git rev-parse HEAD^) = $(git rev-parse branch1) && | |
148 | test $(git rev-parse I) = $(git rev-parse branch2) | |
149 | ' | |
150 | ||
1b1dce4b JS |
151 | test_expect_success 'rebase on top of a non-conflicting commit' ' |
152 | git checkout branch1 && | |
153 | git tag original-branch1 && | |
154 | git rebase -i branch2 && | |
155 | test file6 = $(git diff --name-only original-branch1) && | |
ab736792 SB |
156 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" && |
157 | test $(git rev-parse I) = $(git rev-parse branch2) && | |
1b1dce4b JS |
158 | test $(git rev-parse I) = $(git rev-parse HEAD~2) |
159 | ' | |
160 | ||
68a163c9 JS |
161 | test_expect_success 'reflog for the branch shows state before rebase' ' |
162 | test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1) | |
163 | ' | |
164 | ||
1b1dce4b JS |
165 | test_expect_success 'exchange two commits' ' |
166 | FAKE_LINES="2 1" git rebase -i HEAD~2 && | |
b4ce54fc JK |
167 | test H = $(git cat-file commit HEAD^ | sed -ne \$p) && |
168 | test G = $(git cat-file commit HEAD | sed -ne \$p) | |
1b1dce4b JS |
169 | ' |
170 | ||
171 | cat > expect << EOF | |
172 | diff --git a/file1 b/file1 | |
163f3925 | 173 | index f70f10e..fd79235 100644 |
1b1dce4b JS |
174 | --- a/file1 |
175 | +++ b/file1 | |
163f3925 MH |
176 | @@ -1 +1 @@ |
177 | -A | |
178 | +G | |
1b1dce4b JS |
179 | EOF |
180 | ||
181 | cat > expect2 << EOF | |
606475f3 | 182 | <<<<<<< HEAD |
163f3925 | 183 | D |
1b1dce4b | 184 | ======= |
163f3925 | 185 | G |
b4995494 | 186 | >>>>>>> 5d18e54... G |
1b1dce4b JS |
187 | EOF |
188 | ||
189 | test_expect_success 'stop on conflicting pick' ' | |
190 | git tag new-branch1 && | |
ab736792 SB |
191 | test_must_fail git rebase -i master && |
192 | test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" && | |
28ed6e7b | 193 | test_cmp expect .git/rebase-merge/patch && |
82ebb0b6 | 194 | test_cmp expect2 file1 && |
0cb0e143 | 195 | test "$(git diff --name-status | |
ab736792 | 196 | sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 && |
28ed6e7b JS |
197 | test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) && |
198 | test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo) | |
1b1dce4b JS |
199 | ' |
200 | ||
201 | test_expect_success 'abort' ' | |
202 | git rebase --abort && | |
203 | test $(git rev-parse new-branch1) = $(git rev-parse HEAD) && | |
ab736792 | 204 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" && |
2caf20c5 | 205 | test_path_is_missing .git/rebase-merge |
1b1dce4b JS |
206 | ' |
207 | ||
b096374f IWC |
208 | test_expect_success 'abort with error when new base cannot be checked out' ' |
209 | git rm --cached file1 && | |
210 | git commit -m "remove file in base" && | |
211 | test_must_fail git rebase -i master > output 2>&1 && | |
e6c111b4 | 212 | grep "The following untracked working tree files would be overwritten by checkout:" \ |
b096374f | 213 | output && |
e6c111b4 | 214 | grep "file1" output && |
2caf20c5 | 215 | test_path_is_missing .git/rebase-merge && |
b096374f IWC |
216 | git reset --hard HEAD^ |
217 | ' | |
218 | ||
1b1dce4b JS |
219 | test_expect_success 'retain authorship' ' |
220 | echo A > file7 && | |
221 | git add file7 && | |
c54b7817 | 222 | test_tick && |
1b1dce4b JS |
223 | GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && |
224 | git tag twerp && | |
225 | git rebase -i --onto master HEAD^ && | |
226 | git show HEAD | grep "^Author: Twerp Snog" | |
227 | ' | |
228 | ||
229 | test_expect_success 'squash' ' | |
230 | git reset --hard twerp && | |
231 | echo B > file7 && | |
c54b7817 | 232 | test_tick && |
1b1dce4b JS |
233 | GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 && |
234 | echo "******************************" && | |
5065ed29 | 235 | FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \ |
959c0d06 | 236 | git rebase -i --onto master HEAD~2 && |
1b1dce4b JS |
237 | test B = $(cat file7) && |
238 | test $(git rev-parse HEAD^) = $(git rev-parse master) | |
239 | ' | |
240 | ||
241 | test_expect_success 'retain authorship when squashing' ' | |
81ab1cb4 | 242 | git show HEAD | grep "^Author: Twerp Snog" |
1b1dce4b JS |
243 | ' |
244 | ||
34454e85 JS |
245 | test_expect_success '-p handles "no changes" gracefully' ' |
246 | HEAD=$(git rev-parse HEAD) && | |
247 | git rebase -i -p HEAD^ && | |
71d9451e TR |
248 | git update-index --refresh && |
249 | git diff-files --quiet && | |
250 | git diff-index --quiet --cached HEAD -- && | |
34454e85 JS |
251 | test $HEAD = $(git rev-parse HEAD) |
252 | ' | |
253 | ||
cddb42d2 | 254 | test_expect_failure 'exchange two commits with -p' ' |
27ccd8d1 | 255 | git checkout H && |
cddb42d2 JN |
256 | FAKE_LINES="2 1" git rebase -i -p HEAD~2 && |
257 | test H = $(git cat-file commit HEAD^ | sed -ne \$p) && | |
258 | test G = $(git cat-file commit HEAD | sed -ne \$p) | |
259 | ' | |
260 | ||
f09c9b8c JS |
261 | test_expect_success 'preserve merges with -p' ' |
262 | git checkout -b to-be-preserved master^ && | |
263 | : > unrelated-file && | |
264 | git add unrelated-file && | |
265 | test_tick && | |
266 | git commit -m "unrelated" && | |
5352a82b | 267 | git checkout -b another-branch master && |
f09c9b8c JS |
268 | echo B > file1 && |
269 | test_tick && | |
270 | git commit -m J file1 && | |
271 | test_tick && | |
272 | git merge to-be-preserved && | |
273 | echo C > file1 && | |
274 | test_tick && | |
275 | git commit -m K file1 && | |
5352a82b SB |
276 | echo D > file1 && |
277 | test_tick && | |
278 | git commit -m L1 file1 && | |
279 | git checkout HEAD^ && | |
280 | echo 1 > unrelated-file && | |
281 | test_tick && | |
282 | git commit -m L2 unrelated-file && | |
283 | test_tick && | |
284 | git merge another-branch && | |
285 | echo E > file1 && | |
286 | test_tick && | |
287 | git commit -m M file1 && | |
288 | git checkout -b to-be-rebased && | |
18640d99 | 289 | test_tick && |
f09c9b8c | 290 | git rebase -i -p --onto branch1 master && |
71d9451e TR |
291 | git update-index --refresh && |
292 | git diff-files --quiet && | |
293 | git diff-index --quiet --cached HEAD -- && | |
5352a82b SB |
294 | test $(git rev-parse HEAD~6) = $(git rev-parse branch1) && |
295 | test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) && | |
296 | test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) && | |
297 | test $(git show HEAD~5:file1) = B && | |
298 | test $(git show HEAD~3:file1) = C && | |
299 | test $(git show HEAD:file1) = E && | |
300 | test $(git show HEAD:unrelated-file) = 1 | |
f09c9b8c JS |
301 | ' |
302 | ||
a96dc01e | 303 | test_expect_success 'edit ancestor with -p' ' |
12bf8283 | 304 | FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 && |
a96dc01e TR |
305 | echo 2 > unrelated-file && |
306 | test_tick && | |
307 | git commit -m L2-modified --amend unrelated-file && | |
308 | git rebase --continue && | |
309 | git update-index --refresh && | |
310 | git diff-files --quiet && | |
311 | git diff-index --quiet --cached HEAD -- && | |
312 | test $(git show HEAD:unrelated-file) = 2 | |
313 | ' | |
314 | ||
18640d99 JS |
315 | test_expect_success '--continue tries to commit' ' |
316 | test_tick && | |
ab736792 | 317 | test_must_fail git rebase -i --onto new-branch1 HEAD^ && |
18640d99 JS |
318 | echo resolved > file1 && |
319 | git add file1 && | |
320 | FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue && | |
321 | test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) && | |
322 | git show HEAD | grep chouette | |
323 | ' | |
324 | ||
8e4a91bd | 325 | test_expect_success 'verbose flag is heeded, even after --continue' ' |
53f2ffa8 | 326 | git reset --hard master@{1} && |
8e4a91bd | 327 | test_tick && |
ab736792 | 328 | test_must_fail git rebase -v -i --onto new-branch1 HEAD^ && |
8e4a91bd JS |
329 | echo resolved > file1 && |
330 | git add file1 && | |
331 | git rebase --continue > output && | |
dc801e71 | 332 | grep "^ file1 | 2 +-$" output |
8e4a91bd JS |
333 | ' |
334 | ||
6368f3f8 JS |
335 | test_expect_success 'multi-squash only fires up editor once' ' |
336 | base=$(git rev-parse HEAD~4) && | |
337 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \ | |
959c0d06 | 338 | EXPECT_HEADER_COUNT=4 \ |
6368f3f8 JS |
339 | git rebase -i $base && |
340 | test $base = $(git rev-parse HEAD^) && | |
341 | test 1 = $(git show | grep ONCE | wc -l) | |
342 | ' | |
343 | ||
a25eb139 | 344 | test_expect_success 'multi-fixup does not fire up editor' ' |
0205e72f MH |
345 | git checkout -b multi-fixup E && |
346 | base=$(git rev-parse HEAD~4) && | |
a25eb139 | 347 | FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ |
0205e72f MH |
348 | git rebase -i $base && |
349 | test $base = $(git rev-parse HEAD^) && | |
a25eb139 | 350 | test 0 = $(git show | grep NEVER | wc -l) && |
0205e72f MH |
351 | git checkout to-be-rebased && |
352 | git branch -D multi-fixup | |
353 | ' | |
354 | ||
6bdcd0d2 MH |
355 | test_expect_success 'commit message used after conflict' ' |
356 | git checkout -b conflict-fixup conflict-branch && | |
357 | base=$(git rev-parse HEAD~4) && | |
358 | ( | |
359 | FAKE_LINES="1 fixup 3 fixup 4" && | |
360 | export FAKE_LINES && | |
361 | test_must_fail git rebase -i $base | |
362 | ) && | |
363 | echo three > conflict && | |
364 | git add conflict && | |
365 | FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \ | |
366 | git rebase --continue && | |
367 | test $base = $(git rev-parse HEAD^) && | |
368 | test 1 = $(git show | grep ONCE | wc -l) && | |
369 | git checkout to-be-rebased && | |
370 | git branch -D conflict-fixup | |
371 | ' | |
372 | ||
373 | test_expect_success 'commit message retained after conflict' ' | |
374 | git checkout -b conflict-squash conflict-branch && | |
375 | base=$(git rev-parse HEAD~4) && | |
376 | ( | |
377 | FAKE_LINES="1 fixup 3 squash 4" && | |
378 | export FAKE_LINES && | |
379 | test_must_fail git rebase -i $base | |
380 | ) && | |
381 | echo three > conflict && | |
382 | git add conflict && | |
383 | FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \ | |
384 | git rebase --continue && | |
385 | test $base = $(git rev-parse HEAD^) && | |
386 | test 2 = $(git show | grep TWICE | wc -l) && | |
387 | git checkout to-be-rebased && | |
388 | git branch -D conflict-squash | |
389 | ' | |
390 | ||
0205e72f MH |
391 | cat > expect-squash-fixup << EOF |
392 | B | |
393 | ||
394 | D | |
395 | ||
396 | ONCE | |
397 | EOF | |
398 | ||
399 | test_expect_success 'squash and fixup generate correct log messages' ' | |
400 | git checkout -b squash-fixup E && | |
401 | base=$(git rev-parse HEAD~4) && | |
402 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \ | |
959c0d06 | 403 | EXPECT_HEADER_COUNT=4 \ |
0205e72f MH |
404 | git rebase -i $base && |
405 | git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup && | |
406 | test_cmp expect-squash-fixup actual-squash-fixup && | |
407 | git checkout to-be-rebased && | |
408 | git branch -D squash-fixup | |
409 | ' | |
410 | ||
234b3dae MH |
411 | test_expect_success 'squash ignores comments' ' |
412 | git checkout -b skip-comments E && | |
413 | base=$(git rev-parse HEAD~4) && | |
414 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \ | |
415 | EXPECT_HEADER_COUNT=4 \ | |
416 | git rebase -i $base && | |
417 | test $base = $(git rev-parse HEAD^) && | |
418 | test 1 = $(git show | grep ONCE | wc -l) && | |
419 | git checkout to-be-rebased && | |
420 | git branch -D skip-comments | |
421 | ' | |
422 | ||
423 | test_expect_success 'squash ignores blank lines' ' | |
424 | git checkout -b skip-blank-lines E && | |
425 | base=$(git rev-parse HEAD~4) && | |
426 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \ | |
427 | EXPECT_HEADER_COUNT=4 \ | |
428 | git rebase -i $base && | |
429 | test $base = $(git rev-parse HEAD^) && | |
430 | test 1 = $(git show | grep ONCE | wc -l) && | |
431 | git checkout to-be-rebased && | |
432 | git branch -D skip-blank-lines | |
433 | ' | |
434 | ||
fb47cfbd | 435 | test_expect_success 'squash works as expected' ' |
6c4c44c4 | 436 | git checkout -b squash-works no-conflict-branch && |
fb47cfbd | 437 | one=$(git rev-parse HEAD~3) && |
5065ed29 | 438 | FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \ |
959c0d06 | 439 | git rebase -i HEAD~3 && |
fb47cfbd JS |
440 | test $one = $(git rev-parse HEAD~2) |
441 | ' | |
442 | ||
443 | test_expect_success 'interrupted squash works as expected' ' | |
6c4c44c4 | 444 | git checkout -b interrupted-squash conflict-branch && |
fb47cfbd | 445 | one=$(git rev-parse HEAD~3) && |
ab736792 SB |
446 | ( |
447 | FAKE_LINES="1 squash 3 2" && | |
448 | export FAKE_LINES && | |
449 | test_must_fail git rebase -i HEAD~3 | |
450 | ) && | |
fb47cfbd JS |
451 | (echo one; echo two; echo four) > conflict && |
452 | git add conflict && | |
ab736792 | 453 | test_must_fail git rebase --continue && |
fb47cfbd JS |
454 | echo resolved > conflict && |
455 | git add conflict && | |
456 | git rebase --continue && | |
457 | test $one = $(git rev-parse HEAD~2) | |
458 | ' | |
459 | ||
1d25c8cf | 460 | test_expect_success 'interrupted squash works as expected (case 2)' ' |
6c4c44c4 | 461 | git checkout -b interrupted-squash2 conflict-branch && |
1d25c8cf | 462 | one=$(git rev-parse HEAD~3) && |
ab736792 SB |
463 | ( |
464 | FAKE_LINES="3 squash 1 2" && | |
465 | export FAKE_LINES && | |
466 | test_must_fail git rebase -i HEAD~3 | |
467 | ) && | |
1d25c8cf JS |
468 | (echo one; echo four) > conflict && |
469 | git add conflict && | |
ab736792 | 470 | test_must_fail git rebase --continue && |
1d25c8cf JS |
471 | (echo one; echo two; echo four) > conflict && |
472 | git add conflict && | |
ab736792 | 473 | test_must_fail git rebase --continue && |
1d25c8cf JS |
474 | echo resolved > conflict && |
475 | git add conflict && | |
476 | git rebase --continue && | |
477 | test $one = $(git rev-parse HEAD~2) | |
478 | ' | |
479 | ||
3f213981 | 480 | test_expect_success '--continue tries to commit, even for "edit"' ' |
96ffe892 JS |
481 | echo unrelated > file7 && |
482 | git add file7 && | |
483 | test_tick && | |
484 | git commit -m "unrelated change" && | |
be6ff208 JS |
485 | parent=$(git rev-parse HEAD^) && |
486 | test_tick && | |
487 | FAKE_LINES="edit 1" git rebase -i HEAD^ && | |
488 | echo edited > file7 && | |
489 | git add file7 && | |
490 | FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue && | |
491 | test edited = $(git show HEAD:file7) && | |
492 | git show HEAD | grep chouette && | |
493 | test $parent = $(git rev-parse HEAD^) | |
494 | ' | |
495 | ||
dc7f55cb SB |
496 | test_expect_success 'aborted --continue does not squash commits after "edit"' ' |
497 | old=$(git rev-parse HEAD) && | |
498 | test_tick && | |
499 | FAKE_LINES="edit 1" git rebase -i HEAD^ && | |
500 | echo "edited again" > file7 && | |
501 | git add file7 && | |
502 | ( | |
503 | FAKE_COMMIT_MESSAGE=" " && | |
504 | export FAKE_COMMIT_MESSAGE && | |
505 | test_must_fail git rebase --continue | |
506 | ) && | |
507 | test $old = $(git rev-parse HEAD) && | |
508 | git rebase --abort | |
509 | ' | |
510 | ||
f8aa1b69 SB |
511 | test_expect_success 'auto-amend only edited commits after "edit"' ' |
512 | test_tick && | |
513 | FAKE_LINES="edit 1" git rebase -i HEAD^ && | |
514 | echo "edited again" > file7 && | |
515 | git add file7 && | |
516 | FAKE_COMMIT_MESSAGE="edited file7 again" git commit && | |
517 | echo "and again" > file7 && | |
518 | git add file7 && | |
519 | test_tick && | |
520 | ( | |
521 | FAKE_COMMIT_MESSAGE="and again" && | |
522 | export FAKE_COMMIT_MESSAGE && | |
523 | test_must_fail git rebase --continue | |
524 | ) && | |
525 | git rebase --abort | |
526 | ' | |
527 | ||
ffaaed88 MM |
528 | test_expect_success 'clean error after failed "exec"' ' |
529 | test_tick && | |
530 | test_when_finished "git rebase --abort || :" && | |
531 | ( | |
532 | FAKE_LINES="1 exec_false" && | |
533 | export FAKE_LINES && | |
534 | test_must_fail git rebase -i HEAD^ | |
535 | ) && | |
536 | echo "edited again" > file7 && | |
537 | git add file7 && | |
538 | test_must_fail git rebase --continue 2>error && | |
539 | grep "You have staged changes in your working tree." error | |
540 | ' | |
541 | ||
73697a0b JS |
542 | test_expect_success 'rebase a detached HEAD' ' |
543 | grandparent=$(git rev-parse HEAD~2) && | |
544 | git checkout $(git rev-parse HEAD) && | |
545 | test_tick && | |
546 | FAKE_LINES="2 1" git rebase -i HEAD~2 && | |
547 | test $grandparent = $(git rev-parse HEAD~2) | |
548 | ' | |
549 | ||
752527f5 JS |
550 | test_expect_success 'rebase a commit violating pre-commit' ' |
551 | ||
552 | mkdir -p .git/hooks && | |
553 | PRE_COMMIT=.git/hooks/pre-commit && | |
554 | echo "#!/bin/sh" > $PRE_COMMIT && | |
555 | echo "test -z \"\$(git diff --cached --check)\"" >> $PRE_COMMIT && | |
556 | chmod a+x $PRE_COMMIT && | |
557 | echo "monde! " >> file1 && | |
558 | test_tick && | |
ab736792 | 559 | test_must_fail git commit -m doesnt-verify file1 && |
752527f5 JS |
560 | git commit -m doesnt-verify --no-verify file1 && |
561 | test_tick && | |
562 | FAKE_LINES=2 git rebase -i HEAD~2 | |
563 | ||
564 | ' | |
565 | ||
077b725f JH |
566 | test_expect_success 'rebase with a file named HEAD in worktree' ' |
567 | ||
568 | rm -fr .git/hooks && | |
569 | git reset --hard && | |
570 | git checkout -b branch3 A && | |
571 | ||
572 | ( | |
573 | GIT_AUTHOR_NAME="Squashed Away" && | |
574 | export GIT_AUTHOR_NAME && | |
575 | >HEAD && | |
576 | git add HEAD && | |
577 | git commit -m "Add head" && | |
578 | >BODY && | |
579 | git add BODY && | |
580 | git commit -m "Add body" | |
581 | ) && | |
582 | ||
583 | FAKE_LINES="1 squash 2" git rebase -i to-be-rebased && | |
584 | test "$(git show -s --pretty=format:%an)" = "Squashed Away" | |
585 | ||
586 | ' | |
587 | ||
ff74126c JS |
588 | test_expect_success 'do "noop" when there is nothing to cherry-pick' ' |
589 | ||
590 | git checkout -b branch4 HEAD && | |
591 | GIT_EDITOR=: git commit --amend \ | |
2dec68cf | 592 | --author="Somebody else <somebody@else.com>" && |
ff74126c JS |
593 | test $(git rev-parse branch3) != $(git rev-parse branch4) && |
594 | git rebase -i branch3 && | |
595 | test $(git rev-parse branch3) = $(git rev-parse branch4) | |
596 | ||
597 | ' | |
598 | ||
96747696 JH |
599 | test_expect_success 'submodule rebase setup' ' |
600 | git checkout A && | |
601 | mkdir sub && | |
602 | ( | |
603 | cd sub && git init && >elif && | |
604 | git add elif && git commit -m "submodule initial" | |
605 | ) && | |
606 | echo 1 >file1 && | |
2dec68cf | 607 | git add file1 sub && |
96747696 JH |
608 | test_tick && |
609 | git commit -m "One" && | |
610 | echo 2 >file1 && | |
611 | test_tick && | |
612 | git commit -a -m "Two" && | |
613 | ( | |
614 | cd sub && echo 3 >elif && | |
615 | git commit -a -m "submodule second" | |
616 | ) && | |
617 | test_tick && | |
618 | git commit -a -m "Three changes submodule" | |
619 | ' | |
620 | ||
94c88ede | 621 | test_expect_success 'submodule rebase -i' ' |
96747696 JH |
622 | FAKE_LINES="1 squash 2 3" git rebase -i A |
623 | ' | |
624 | ||
a6754cda JK |
625 | test_expect_success 'submodule conflict setup' ' |
626 | git tag submodule-base && | |
627 | git checkout HEAD^ && | |
628 | ( | |
629 | cd sub && git checkout HEAD^ && echo 4 >elif && | |
630 | git add elif && git commit -m "submodule conflict" | |
631 | ) && | |
632 | git add sub && | |
633 | test_tick && | |
634 | git commit -m "Conflict in submodule" && | |
635 | git tag submodule-topic | |
636 | ' | |
637 | ||
638 | test_expect_success 'rebase -i continue with only submodule staged' ' | |
639 | test_must_fail git rebase -i submodule-base && | |
640 | git add sub && | |
641 | git rebase --continue && | |
642 | test $(git rev-parse submodule-base) != $(git rev-parse HEAD) | |
643 | ' | |
644 | ||
645 | test_expect_success 'rebase -i continue with unstaged submodule' ' | |
646 | git checkout submodule-topic && | |
647 | git reset --hard && | |
648 | test_must_fail git rebase -i submodule-base && | |
649 | git reset && | |
650 | git rebase --continue && | |
651 | test $(git rev-parse submodule-base) = $(git rev-parse HEAD) | |
652 | ' | |
653 | ||
0e757e30 JS |
654 | test_expect_success 'avoid unnecessary reset' ' |
655 | git checkout master && | |
a6754cda | 656 | git reset --hard && |
0e757e30 JS |
657 | test-chmtime =123456789 file3 && |
658 | git update-index --refresh && | |
659 | HEAD=$(git rev-parse HEAD) && | |
660 | git rebase -i HEAD~4 && | |
661 | test $HEAD = $(git rev-parse HEAD) && | |
662 | MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') && | |
663 | test 123456789 = $MTIME | |
664 | ' | |
665 | ||
6741aa6c BG |
666 | test_expect_success 'reword' ' |
667 | git checkout -b reword-branch master && | |
668 | FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A && | |
669 | git show HEAD | grep "E changed" && | |
670 | test $(git rev-parse master) != $(git rev-parse HEAD) && | |
671 | test $(git rev-parse master^) = $(git rev-parse HEAD^) && | |
672 | FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A && | |
673 | git show HEAD^ | grep "D changed" && | |
674 | FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A && | |
675 | git show HEAD~3 | grep "B changed" && | |
676 | FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A && | |
677 | git show HEAD~2 | grep "C changed" | |
678 | ' | |
679 | ||
eb2151bb TR |
680 | test_expect_success 'rebase -i can copy notes' ' |
681 | git config notes.rewrite.rebase true && | |
682 | git config notes.rewriteRef "refs/notes/*" && | |
683 | test_commit n1 && | |
684 | test_commit n2 && | |
685 | test_commit n3 && | |
686 | git notes add -m"a note" n3 && | |
6f87f038 | 687 | git rebase -i --onto n1 n2 && |
eb2151bb TR |
688 | test "a note" = "$(git notes show HEAD)" |
689 | ' | |
690 | ||
691 | cat >expect <<EOF | |
692 | an earlier note | |
d4990c4b | 693 | |
eb2151bb TR |
694 | a note |
695 | EOF | |
696 | ||
697 | test_expect_success 'rebase -i can copy notes over a fixup' ' | |
698 | git reset --hard n3 && | |
699 | git notes add -m"an earlier note" n2 && | |
700 | GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 && | |
701 | git notes show > output && | |
702 | test_cmp expect output | |
703 | ' | |
704 | ||
2ec33cdd DO |
705 | test_expect_success 'rebase while detaching HEAD' ' |
706 | git symbolic-ref HEAD && | |
707 | grandparent=$(git rev-parse HEAD~2) && | |
708 | test_tick && | |
709 | FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 && | |
710 | test $grandparent = $(git rev-parse HEAD~2) && | |
711 | test_must_fail git symbolic-ref HEAD | |
712 | ' | |
713 | ||
b4995494 MB |
714 | test_tick # Ensure that the rebased commits get a different timestamp. |
715 | test_expect_success 'always cherry-pick with --no-ff' ' | |
716 | git checkout no-ff-branch && | |
717 | git tag original-no-ff-branch && | |
718 | git rebase -i --no-ff A && | |
719 | touch empty && | |
720 | for p in 0 1 2 | |
721 | do | |
722 | test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) && | |
723 | git diff HEAD~$p original-no-ff-branch~$p > out && | |
724 | test_cmp empty out | |
725 | done && | |
726 | test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) && | |
727 | git diff HEAD~3 original-no-ff-branch~3 > out && | |
728 | test_cmp empty out | |
729 | ' | |
730 | ||
57f2b6b2 JH |
731 | test_expect_success 'set up commits with funny messages' ' |
732 | git checkout -b funny A && | |
733 | echo >>file1 && | |
734 | test_tick && | |
735 | git commit -a -m "end with slash\\" && | |
736 | echo >>file1 && | |
737 | test_tick && | |
938791cd BC |
738 | git commit -a -m "something (\000) that looks like octal" && |
739 | echo >>file1 && | |
740 | test_tick && | |
741 | git commit -a -m "something (\n) that looks like a newline" && | |
742 | echo >>file1 && | |
743 | test_tick && | |
57f2b6b2 JH |
744 | git commit -a -m "another commit" |
745 | ' | |
746 | ||
747 | test_expect_success 'rebase-i history with funny messages' ' | |
748 | git rev-list A..funny >expect && | |
749 | test_tick && | |
938791cd | 750 | FAKE_LINES="1 2 3 4" git rebase -i A && |
57f2b6b2 JH |
751 | git rev-list A.. >actual && |
752 | test_cmp expect actual | |
753 | ' | |
754 | ||
c2145384 LK |
755 | |
756 | test_expect_success 'prepare for rebase -i --exec' ' | |
757 | git checkout master && | |
758 | git checkout -b execute && | |
759 | test_commit one_exec main.txt one_exec && | |
760 | test_commit two_exec main.txt two_exec && | |
761 | test_commit three_exec main.txt three_exec | |
762 | ' | |
763 | ||
764 | ||
765 | test_expect_success 'running "git rebase -i --exec git show HEAD"' ' | |
766 | git rebase -i --exec "git show HEAD" HEAD~2 >actual && | |
767 | ( | |
768 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
769 | export FAKE_LINES && | |
770 | git rebase -i HEAD~2 >expect | |
771 | ) && | |
772 | sed -e "1,9d" expect >expected && | |
773 | test_cmp expected actual | |
774 | ' | |
775 | ||
776 | ||
777 | test_expect_success 'running "git rebase --exec git show HEAD -i"' ' | |
778 | git reset --hard execute && | |
779 | git rebase --exec "git show HEAD" -i HEAD~2 >actual && | |
780 | ( | |
781 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
782 | export FAKE_LINES && | |
783 | git rebase -i HEAD~2 >expect | |
784 | ) && | |
785 | sed -e "1,9d" expect >expected && | |
786 | test_cmp expected actual | |
787 | ' | |
788 | ||
789 | ||
790 | test_expect_success 'running "git rebase -ix git show HEAD"' ' | |
791 | git reset --hard execute && | |
792 | git rebase -ix "git show HEAD" HEAD~2 >actual && | |
793 | ( | |
794 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
795 | export FAKE_LINES && | |
796 | git rebase -i HEAD~2 >expect | |
797 | ) && | |
798 | sed -e "1,9d" expect >expected && | |
799 | test_cmp expected actual | |
800 | ' | |
801 | ||
802 | ||
803 | test_expect_success 'rebase -ix with several <CMD>' ' | |
804 | git reset --hard execute && | |
805 | git rebase -ix "git show HEAD; pwd" HEAD~2 >actual && | |
806 | ( | |
807 | FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" && | |
808 | export FAKE_LINES && | |
809 | git rebase -i HEAD~2 >expect | |
810 | ) && | |
811 | sed -e "1,9d" expect >expected && | |
812 | test_cmp expected actual | |
813 | ' | |
814 | ||
815 | ||
816 | test_expect_success 'rebase -ix with several instances of --exec' ' | |
817 | git reset --hard execute && | |
818 | git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual && | |
819 | ( | |
820 | FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2 | |
821 | exec_git_show_HEAD exec_pwd" && | |
822 | export FAKE_LINES && | |
823 | git rebase -i HEAD~2 >expect | |
824 | ) && | |
825 | sed -e "1,11d" expect >expected && | |
826 | test_cmp expected actual | |
827 | ' | |
828 | ||
829 | ||
830 | test_expect_success 'rebase -ix with --autosquash' ' | |
831 | git reset --hard execute && | |
832 | git checkout -b autosquash && | |
833 | echo second >second.txt && | |
834 | git add second.txt && | |
835 | git commit -m "fixup! two_exec" && | |
836 | echo bis >bis.txt && | |
837 | git add bis.txt && | |
838 | git commit -m "fixup! two_exec" && | |
839 | ( | |
840 | git checkout -b autosquash_actual && | |
841 | git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual | |
842 | ) && | |
843 | git checkout autosquash && | |
844 | ( | |
845 | git checkout -b autosquash_expected && | |
846 | FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
847 | export FAKE_LINES && | |
848 | git rebase -i HEAD~4 >expect | |
849 | ) && | |
850 | sed -e "1,13d" expect >expected && | |
851 | test_cmp expected actual | |
852 | ' | |
853 | ||
854 | ||
855 | test_expect_success 'rebase --exec without -i shows error message' ' | |
856 | git reset --hard execute && | |
857 | test_must_fail git rebase --exec "git show HEAD" HEAD~2 2>actual && | |
465d6a00 | 858 | echo "The --exec option must be used with the --interactive option" >expected && |
c2145384 LK |
859 | test_i18ncmp expected actual |
860 | ' | |
861 | ||
862 | ||
863 | test_expect_success 'rebase -i --exec without <CMD>' ' | |
864 | git reset --hard execute && | |
865 | test_must_fail git rebase -i --exec 2>tmp && | |
866 | sed -e "1d" tmp >actual && | |
867 | test_must_fail git rebase -h >expected && | |
868 | test_cmp expected actual && | |
869 | git checkout master | |
870 | ' | |
871 | ||
b64b7feb CW |
872 | test_expect_success 'rebase -i --root re-order and drop commits' ' |
873 | git checkout E && | |
874 | FAKE_LINES="3 1 2 5" git rebase -i --root && | |
875 | test E = $(git cat-file commit HEAD | sed -ne \$p) && | |
876 | test B = $(git cat-file commit HEAD^ | sed -ne \$p) && | |
877 | test A = $(git cat-file commit HEAD^^ | sed -ne \$p) && | |
878 | test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) && | |
879 | test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ ) | |
880 | ' | |
881 | ||
882 | test_expect_success 'rebase -i --root retain root commit author and message' ' | |
883 | git checkout A && | |
884 | echo B >file7 && | |
885 | git add file7 && | |
886 | GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && | |
887 | FAKE_LINES="2" git rebase -i --root && | |
888 | git cat-file commit HEAD | grep -q "^author Twerp Snog" && | |
889 | git cat-file commit HEAD | grep -q "^different author$" | |
890 | ' | |
891 | ||
892 | test_expect_success 'rebase -i --root temporary sentinel commit' ' | |
893 | git checkout B && | |
994fd91d MG |
894 | ( |
895 | FAKE_LINES="2" && | |
896 | export FAKE_LINES && | |
897 | test_must_fail git rebase -i --root | |
898 | ) && | |
b64b7feb CW |
899 | git cat-file commit HEAD | grep "^tree 4b825dc642cb" && |
900 | git rebase --abort | |
901 | ' | |
902 | ||
2147f844 CW |
903 | test_expect_success 'rebase -i --root fixup root commit' ' |
904 | git checkout B && | |
905 | FAKE_LINES="1 fixup 2" git rebase -i --root && | |
906 | test A = $(git cat-file commit HEAD | sed -ne \$p) && | |
907 | test B = $(git show HEAD:file1) && | |
908 | test 0 = $(git cat-file commit HEAD | grep -c ^parent\ ) | |
909 | ' | |
910 | ||
9f4981ba AW |
911 | test_expect_success 'rebase --edit-todo does not works on non-interactive rebase' ' |
912 | git reset --hard && | |
913 | git checkout conflict-branch && | |
914 | test_must_fail git rebase --onto HEAD~2 HEAD~ && | |
915 | test_must_fail git rebase --edit-todo && | |
916 | git rebase --abort | |
917 | ' | |
918 | ||
919 | test_expect_success 'rebase --edit-todo can be used to modify todo' ' | |
920 | git reset --hard && | |
921 | git checkout no-conflict-branch^0 && | |
922 | FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 && | |
923 | FAKE_LINES="2 1" git rebase --edit-todo && | |
924 | git rebase --continue | |
925 | test M = $(git cat-file commit HEAD^ | sed -ne \$p) && | |
926 | test L = $(git cat-file commit HEAD | sed -ne \$p) | |
927 | ' | |
928 | ||
26cd160c RR |
929 | test_expect_success 'rebase -i produces readable reflog' ' |
930 | git reset --hard && | |
931 | git branch -f branch-reflog-test H && | |
932 | git rebase -i --onto I F branch-reflog-test && | |
933 | cat >expect <<-\EOF && | |
934 | rebase -i (start): checkout I | |
935 | rebase -i (pick): G | |
936 | rebase -i (pick): H | |
937 | rebase -i (finish): returning to refs/heads/branch-reflog-test | |
938 | EOF | |
939 | tail -n 4 .git/logs/HEAD | | |
940 | sed -e "s/.* //" >actual && | |
941 | test_cmp expect actual | |
942 | ' | |
943 | ||
180bad3d JK |
944 | test_expect_success 'rebase -i respects core.commentchar' ' |
945 | git reset --hard && | |
946 | git checkout E^0 && | |
aac6c2f4 | 947 | test_config core.commentchar "\\" && |
180bad3d JK |
948 | write_script remove-all-but-first.sh <<-\EOF && |
949 | sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" && | |
950 | mv "$1.tmp" "$1" | |
951 | EOF | |
952 | test_set_editor "$(pwd)/remove-all-but-first.sh" && | |
953 | git rebase -i B && | |
954 | test B = $(git cat-file commit HEAD^ | sed -ne \$p) | |
955 | ' | |
956 | ||
2e6e276d | 957 | test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' ' |
6567dc05 RR |
958 | test_when_finished "git branch -D torebase" && |
959 | git checkout -b torebase branch1 && | |
960 | upstream=$(git rev-parse ":/J") && | |
961 | onto=$(git rev-parse ":/A") && | |
962 | git rebase --onto $onto $upstream && | |
963 | git reset --hard branch1 && | |
964 | git rebase --onto ":/A" ":/J" && | |
965 | git checkout branch1 | |
966 | ' | |
967 | ||
db2b3b82 AF |
968 | test_expect_success 'rebase -i with --strategy and -X' ' |
969 | git checkout -b conflict-merge-use-theirs conflict-branch && | |
970 | git reset --hard HEAD^ && | |
971 | echo five >conflict && | |
972 | echo Z >file1 && | |
973 | git commit -a -m "one file conflict" && | |
974 | EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch && | |
975 | test $(git show conflict-branch:conflict) = $(cat conflict) && | |
976 | test $(cat file1) = Z | |
977 | ' | |
978 | ||
1b1dce4b | 979 | test_done |