]>
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 | |
b4995494 MB |
32 | # WARNING: Modifications to the initial repository can change the SHA ID used |
33 | # in the expect2 file for the 'stop on conflicting pick' test. | |
34 | ||
1b1dce4b | 35 | test_expect_success 'setup' ' |
163f3925 MH |
36 | test_commit A file1 && |
37 | test_commit B file1 && | |
38 | test_commit C file2 && | |
39 | test_commit D file1 && | |
40 | test_commit E file3 && | |
1b1dce4b | 41 | git checkout -b branch1 A && |
163f3925 MH |
42 | test_commit F file4 && |
43 | test_commit G file1 && | |
44 | test_commit H file5 && | |
1b1dce4b | 45 | git checkout -b branch2 F && |
2dec68cf | 46 | test_commit I file6 && |
6c4c44c4 | 47 | git checkout -b conflict-branch A && |
391a825f JN |
48 | test_commit one conflict && |
49 | test_commit two conflict && | |
50 | test_commit three conflict && | |
51 | test_commit four conflict && | |
6c4c44c4 | 52 | git checkout -b no-conflict-branch A && |
391a825f JN |
53 | test_commit J fileJ && |
54 | test_commit K fileK && | |
55 | test_commit L fileL && | |
56 | test_commit M fileM && | |
b4995494 | 57 | git checkout -b no-ff-branch A && |
391a825f JN |
58 | test_commit N fileN && |
59 | test_commit O fileO && | |
60 | test_commit P fileP | |
1b1dce4b JS |
61 | ' |
62 | ||
fa90ab4a | 63 | # "exec" commands are run with the user shell by default, but this may |
cd035b1c | 64 | # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work |
386aad5a | 65 | # to create a file. Unsetting SHELL avoids such non-portable behavior |
5cd3e107 | 66 | # in tests. It must be exported for it to take effect where needed. |
cd035b1c | 67 | SHELL= |
5cd3e107 | 68 | export SHELL |
cd035b1c | 69 | |
bd46cfae MT |
70 | test_expect_success 'rebase --keep-empty' ' |
71 | git checkout -b emptybranch master && | |
72 | git commit --allow-empty -m "empty" && | |
73 | git rebase --keep-empty -i HEAD~2 && | |
74 | git log --oneline >actual && | |
75 | test_line_count = 6 actual | |
76 | ' | |
77 | ||
cd035b1c MM |
78 | test_expect_success 'rebase -i with the exec command' ' |
79 | git checkout master && | |
80 | ( | |
31cd8275 | 81 | set_fake_editor && |
cd035b1c MM |
82 | FAKE_LINES="1 exec_>touch-one |
83 | 2 exec_>touch-two exec_false exec_>touch-three | |
84 | 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" && | |
85 | export FAKE_LINES && | |
86 | test_must_fail git rebase -i A | |
87 | ) && | |
2caf20c5 MM |
88 | test_path_is_file touch-one && |
89 | test_path_is_file touch-two && | |
90 | test_path_is_missing touch-three " (should have stopped before)" && | |
5c947e2c | 91 | test_cmp_rev C HEAD && |
cd035b1c | 92 | git rebase --continue && |
2caf20c5 MM |
93 | test_path_is_file touch-three && |
94 | test_path_is_file "touch-file name with spaces" && | |
95 | test_path_is_file touch-after-semicolon && | |
5c947e2c | 96 | test_cmp_rev master HEAD && |
cd035b1c MM |
97 | rm -f touch-* |
98 | ' | |
99 | ||
100 | test_expect_success 'rebase -i with the exec command runs from tree root' ' | |
101 | git checkout master && | |
c2e0940b | 102 | mkdir subdir && (cd subdir && |
31cd8275 | 103 | set_fake_editor && |
cd035b1c | 104 | FAKE_LINES="1 exec_>touch-subdir" \ |
c2e0940b JL |
105 | git rebase -i HEAD^ |
106 | ) && | |
2caf20c5 | 107 | test_path_is_file touch-subdir && |
cd035b1c MM |
108 | rm -fr subdir |
109 | ' | |
110 | ||
111 | test_expect_success 'rebase -i with the exec command checks tree cleanness' ' | |
112 | git checkout master && | |
31cd8275 | 113 | set_fake_editor && |
512477b1 | 114 | test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^ && |
5c947e2c | 115 | test_cmp_rev master^ HEAD && |
cd035b1c MM |
116 | git reset --hard && |
117 | git rebase --continue | |
118 | ' | |
119 | ||
ecfe1ea9 JS |
120 | test_expect_success 'rebase -i with exec of inexistent command' ' |
121 | git checkout master && | |
122 | test_when_finished "git rebase --abort" && | |
31cd8275 | 123 | set_fake_editor && |
512477b1 DT |
124 | test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \ |
125 | git rebase -i HEAD^ >actual 2>&1 && | |
ecfe1ea9 JS |
126 | ! grep "Maybe git-rebase is broken" actual |
127 | ' | |
128 | ||
1b1dce4b | 129 | test_expect_success 'no changes are a nop' ' |
6c4c44c4 | 130 | git checkout branch2 && |
31cd8275 | 131 | set_fake_editor && |
1b1dce4b | 132 | git rebase -i F && |
ab736792 | 133 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && |
1b1dce4b JS |
134 | test $(git rev-parse I) = $(git rev-parse HEAD) |
135 | ' | |
136 | ||
c9e65892 JS |
137 | test_expect_success 'test the [branch] option' ' |
138 | git checkout -b dead-end && | |
139 | git rm file6 && | |
140 | git commit -m "stop here" && | |
31cd8275 | 141 | set_fake_editor && |
c9e65892 | 142 | git rebase -i F branch2 && |
ab736792 SB |
143 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && |
144 | test $(git rev-parse I) = $(git rev-parse branch2) && | |
c9e65892 JS |
145 | test $(git rev-parse I) = $(git rev-parse HEAD) |
146 | ' | |
147 | ||
ab736792 SB |
148 | test_expect_success 'test --onto <branch>' ' |
149 | git checkout -b test-onto branch2 && | |
31cd8275 | 150 | set_fake_editor && |
ab736792 SB |
151 | git rebase -i --onto branch1 F && |
152 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" && | |
153 | test $(git rev-parse HEAD^) = $(git rev-parse branch1) && | |
154 | test $(git rev-parse I) = $(git rev-parse branch2) | |
155 | ' | |
156 | ||
1b1dce4b JS |
157 | test_expect_success 'rebase on top of a non-conflicting commit' ' |
158 | git checkout branch1 && | |
159 | git tag original-branch1 && | |
31cd8275 | 160 | set_fake_editor && |
1b1dce4b JS |
161 | git rebase -i branch2 && |
162 | test file6 = $(git diff --name-only original-branch1) && | |
ab736792 SB |
163 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" && |
164 | test $(git rev-parse I) = $(git rev-parse branch2) && | |
1b1dce4b JS |
165 | test $(git rev-parse I) = $(git rev-parse HEAD~2) |
166 | ' | |
167 | ||
68a163c9 JS |
168 | test_expect_success 'reflog for the branch shows state before rebase' ' |
169 | test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1) | |
170 | ' | |
171 | ||
1ceb9dfa PW |
172 | test_expect_success 'reflog for the branch shows correct finish message' ' |
173 | printf "rebase -i (finish): refs/heads/branch1 onto %s\n" \ | |
174 | "$(git rev-parse branch2)" >expected && | |
175 | git log -g --pretty=%gs -1 refs/heads/branch1 >actual && | |
176 | test_cmp expected actual | |
177 | ' | |
178 | ||
1b1dce4b | 179 | test_expect_success 'exchange two commits' ' |
31cd8275 | 180 | set_fake_editor && |
1b1dce4b | 181 | FAKE_LINES="2 1" git rebase -i HEAD~2 && |
b4ce54fc JK |
182 | test H = $(git cat-file commit HEAD^ | sed -ne \$p) && |
183 | test G = $(git cat-file commit HEAD | sed -ne \$p) | |
1b1dce4b JS |
184 | ' |
185 | ||
186 | cat > expect << EOF | |
187 | diff --git a/file1 b/file1 | |
163f3925 | 188 | index f70f10e..fd79235 100644 |
1b1dce4b JS |
189 | --- a/file1 |
190 | +++ b/file1 | |
163f3925 MH |
191 | @@ -1 +1 @@ |
192 | -A | |
193 | +G | |
1b1dce4b JS |
194 | EOF |
195 | ||
196 | cat > expect2 << EOF | |
606475f3 | 197 | <<<<<<< HEAD |
163f3925 | 198 | D |
1b1dce4b | 199 | ======= |
163f3925 | 200 | G |
b4995494 | 201 | >>>>>>> 5d18e54... G |
1b1dce4b JS |
202 | EOF |
203 | ||
204 | test_expect_success 'stop on conflicting pick' ' | |
205 | git tag new-branch1 && | |
31cd8275 | 206 | set_fake_editor && |
ab736792 SB |
207 | test_must_fail git rebase -i master && |
208 | test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" && | |
28ed6e7b | 209 | test_cmp expect .git/rebase-merge/patch && |
82ebb0b6 | 210 | test_cmp expect2 file1 && |
0cb0e143 | 211 | test "$(git diff --name-status | |
ab736792 | 212 | sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 && |
28ed6e7b JS |
213 | test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) && |
214 | test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo) | |
1b1dce4b JS |
215 | ' |
216 | ||
217 | test_expect_success 'abort' ' | |
218 | git rebase --abort && | |
219 | test $(git rev-parse new-branch1) = $(git rev-parse HEAD) && | |
ab736792 | 220 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" && |
2caf20c5 | 221 | test_path_is_missing .git/rebase-merge |
1b1dce4b JS |
222 | ' |
223 | ||
b096374f IWC |
224 | test_expect_success 'abort with error when new base cannot be checked out' ' |
225 | git rm --cached file1 && | |
226 | git commit -m "remove file in base" && | |
31cd8275 | 227 | set_fake_editor && |
b096374f | 228 | test_must_fail git rebase -i master > output 2>&1 && |
e5c1272c | 229 | test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \ |
b096374f | 230 | output && |
e5c1272c | 231 | test_i18ngrep "file1" output && |
2caf20c5 | 232 | test_path_is_missing .git/rebase-merge && |
b096374f IWC |
233 | git reset --hard HEAD^ |
234 | ' | |
235 | ||
1b1dce4b JS |
236 | test_expect_success 'retain authorship' ' |
237 | echo A > file7 && | |
238 | git add file7 && | |
c54b7817 | 239 | test_tick && |
1b1dce4b JS |
240 | GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && |
241 | git tag twerp && | |
31cd8275 | 242 | set_fake_editor && |
1b1dce4b JS |
243 | git rebase -i --onto master HEAD^ && |
244 | git show HEAD | grep "^Author: Twerp Snog" | |
245 | ' | |
246 | ||
a2a20b0d JS |
247 | test_expect_success 'retain authorship w/ conflicts' ' |
248 | git reset --hard twerp && | |
249 | test_commit a conflict a conflict-a && | |
250 | git reset --hard twerp && | |
251 | GIT_AUTHOR_NAME=AttributeMe \ | |
252 | test_commit b conflict b conflict-b && | |
253 | set_fake_editor && | |
254 | test_must_fail git rebase -i conflict-a && | |
255 | echo resolved >conflict && | |
256 | git add conflict && | |
257 | git rebase --continue && | |
258 | test $(git rev-parse conflict-a^0) = $(git rev-parse HEAD^) && | |
259 | git show >out && | |
260 | grep AttributeMe out | |
261 | ' | |
262 | ||
1b1dce4b JS |
263 | test_expect_success 'squash' ' |
264 | git reset --hard twerp && | |
265 | echo B > file7 && | |
c54b7817 | 266 | test_tick && |
1b1dce4b JS |
267 | GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 && |
268 | echo "******************************" && | |
31cd8275 | 269 | set_fake_editor && |
5065ed29 | 270 | FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \ |
959c0d06 | 271 | git rebase -i --onto master HEAD~2 && |
1b1dce4b JS |
272 | test B = $(cat file7) && |
273 | test $(git rev-parse HEAD^) = $(git rev-parse master) | |
274 | ' | |
275 | ||
276 | test_expect_success 'retain authorship when squashing' ' | |
81ab1cb4 | 277 | git show HEAD | grep "^Author: Twerp Snog" |
1b1dce4b JS |
278 | ' |
279 | ||
34454e85 JS |
280 | test_expect_success '-p handles "no changes" gracefully' ' |
281 | HEAD=$(git rev-parse HEAD) && | |
31cd8275 | 282 | set_fake_editor && |
34454e85 | 283 | git rebase -i -p HEAD^ && |
71d9451e TR |
284 | git update-index --refresh && |
285 | git diff-files --quiet && | |
286 | git diff-index --quiet --cached HEAD -- && | |
34454e85 JS |
287 | test $HEAD = $(git rev-parse HEAD) |
288 | ' | |
289 | ||
cddb42d2 | 290 | test_expect_failure 'exchange two commits with -p' ' |
27ccd8d1 | 291 | git checkout H && |
31cd8275 | 292 | set_fake_editor && |
cddb42d2 JN |
293 | FAKE_LINES="2 1" git rebase -i -p HEAD~2 && |
294 | test H = $(git cat-file commit HEAD^ | sed -ne \$p) && | |
295 | test G = $(git cat-file commit HEAD | sed -ne \$p) | |
296 | ' | |
297 | ||
f09c9b8c JS |
298 | test_expect_success 'preserve merges with -p' ' |
299 | git checkout -b to-be-preserved master^ && | |
300 | : > unrelated-file && | |
301 | git add unrelated-file && | |
302 | test_tick && | |
303 | git commit -m "unrelated" && | |
5352a82b | 304 | git checkout -b another-branch master && |
f09c9b8c JS |
305 | echo B > file1 && |
306 | test_tick && | |
307 | git commit -m J file1 && | |
308 | test_tick && | |
309 | git merge to-be-preserved && | |
310 | echo C > file1 && | |
311 | test_tick && | |
312 | git commit -m K file1 && | |
5352a82b SB |
313 | echo D > file1 && |
314 | test_tick && | |
315 | git commit -m L1 file1 && | |
316 | git checkout HEAD^ && | |
317 | echo 1 > unrelated-file && | |
318 | test_tick && | |
319 | git commit -m L2 unrelated-file && | |
320 | test_tick && | |
321 | git merge another-branch && | |
322 | echo E > file1 && | |
323 | test_tick && | |
324 | git commit -m M file1 && | |
325 | git checkout -b to-be-rebased && | |
18640d99 | 326 | test_tick && |
31cd8275 | 327 | set_fake_editor && |
f09c9b8c | 328 | git rebase -i -p --onto branch1 master && |
71d9451e TR |
329 | git update-index --refresh && |
330 | git diff-files --quiet && | |
331 | git diff-index --quiet --cached HEAD -- && | |
5352a82b SB |
332 | test $(git rev-parse HEAD~6) = $(git rev-parse branch1) && |
333 | test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) && | |
334 | test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) && | |
335 | test $(git show HEAD~5:file1) = B && | |
336 | test $(git show HEAD~3:file1) = C && | |
337 | test $(git show HEAD:file1) = E && | |
338 | test $(git show HEAD:unrelated-file) = 1 | |
f09c9b8c JS |
339 | ' |
340 | ||
a96dc01e | 341 | test_expect_success 'edit ancestor with -p' ' |
31cd8275 | 342 | set_fake_editor && |
12bf8283 | 343 | FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 && |
a96dc01e TR |
344 | echo 2 > unrelated-file && |
345 | test_tick && | |
346 | git commit -m L2-modified --amend unrelated-file && | |
347 | git rebase --continue && | |
348 | git update-index --refresh && | |
349 | git diff-files --quiet && | |
350 | git diff-index --quiet --cached HEAD -- && | |
351 | test $(git show HEAD:unrelated-file) = 2 | |
352 | ' | |
353 | ||
18640d99 JS |
354 | test_expect_success '--continue tries to commit' ' |
355 | test_tick && | |
31cd8275 | 356 | set_fake_editor && |
ab736792 | 357 | test_must_fail git rebase -i --onto new-branch1 HEAD^ && |
18640d99 JS |
358 | echo resolved > file1 && |
359 | git add file1 && | |
360 | FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue && | |
361 | test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) && | |
362 | git show HEAD | grep chouette | |
363 | ' | |
364 | ||
8e4a91bd | 365 | test_expect_success 'verbose flag is heeded, even after --continue' ' |
53f2ffa8 | 366 | git reset --hard master@{1} && |
8e4a91bd | 367 | test_tick && |
31cd8275 | 368 | set_fake_editor && |
ab736792 | 369 | test_must_fail git rebase -v -i --onto new-branch1 HEAD^ && |
8e4a91bd JS |
370 | echo resolved > file1 && |
371 | git add file1 && | |
372 | git rebase --continue > output && | |
dc801e71 | 373 | grep "^ file1 | 2 +-$" output |
8e4a91bd JS |
374 | ' |
375 | ||
0d75bfe6 | 376 | test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' ' |
6368f3f8 | 377 | base=$(git rev-parse HEAD~4) && |
31cd8275 | 378 | set_fake_editor && |
6368f3f8 | 379 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \ |
959c0d06 | 380 | EXPECT_HEADER_COUNT=4 \ |
6368f3f8 JS |
381 | git rebase -i $base && |
382 | test $base = $(git rev-parse HEAD^) && | |
383 | test 1 = $(git show | grep ONCE | wc -l) | |
384 | ' | |
385 | ||
0d75bfe6 | 386 | test_expect_success C_LOCALE_OUTPUT 'multi-fixup does not fire up editor' ' |
0205e72f MH |
387 | git checkout -b multi-fixup E && |
388 | base=$(git rev-parse HEAD~4) && | |
31cd8275 | 389 | set_fake_editor && |
a25eb139 | 390 | FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ |
0205e72f MH |
391 | git rebase -i $base && |
392 | test $base = $(git rev-parse HEAD^) && | |
a25eb139 | 393 | test 0 = $(git show | grep NEVER | wc -l) && |
0205e72f MH |
394 | git checkout to-be-rebased && |
395 | git branch -D multi-fixup | |
396 | ' | |
397 | ||
6bdcd0d2 MH |
398 | test_expect_success 'commit message used after conflict' ' |
399 | git checkout -b conflict-fixup conflict-branch && | |
400 | base=$(git rev-parse HEAD~4) && | |
31cd8275 | 401 | set_fake_editor && |
512477b1 | 402 | test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base && |
6bdcd0d2 MH |
403 | echo three > conflict && |
404 | git add conflict && | |
405 | FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \ | |
406 | git rebase --continue && | |
407 | test $base = $(git rev-parse HEAD^) && | |
408 | test 1 = $(git show | grep ONCE | wc -l) && | |
409 | git checkout to-be-rebased && | |
410 | git branch -D conflict-fixup | |
411 | ' | |
412 | ||
413 | test_expect_success 'commit message retained after conflict' ' | |
414 | git checkout -b conflict-squash conflict-branch && | |
415 | base=$(git rev-parse HEAD~4) && | |
31cd8275 | 416 | set_fake_editor && |
512477b1 | 417 | test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base && |
6bdcd0d2 MH |
418 | echo three > conflict && |
419 | git add conflict && | |
420 | FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \ | |
421 | git rebase --continue && | |
422 | test $base = $(git rev-parse HEAD^) && | |
423 | test 2 = $(git show | grep TWICE | wc -l) && | |
424 | git checkout to-be-rebased && | |
425 | git branch -D conflict-squash | |
426 | ' | |
427 | ||
0205e72f MH |
428 | cat > expect-squash-fixup << EOF |
429 | B | |
430 | ||
431 | D | |
432 | ||
433 | ONCE | |
434 | EOF | |
435 | ||
0d75bfe6 | 436 | test_expect_success C_LOCALE_OUTPUT 'squash and fixup generate correct log messages' ' |
0205e72f MH |
437 | git checkout -b squash-fixup E && |
438 | base=$(git rev-parse HEAD~4) && | |
31cd8275 | 439 | set_fake_editor && |
0205e72f | 440 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \ |
959c0d06 | 441 | EXPECT_HEADER_COUNT=4 \ |
0205e72f MH |
442 | git rebase -i $base && |
443 | git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup && | |
444 | test_cmp expect-squash-fixup actual-squash-fixup && | |
445 | git checkout to-be-rebased && | |
446 | git branch -D squash-fixup | |
447 | ' | |
448 | ||
0d75bfe6 | 449 | test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' ' |
234b3dae MH |
450 | git checkout -b skip-comments E && |
451 | base=$(git rev-parse HEAD~4) && | |
31cd8275 | 452 | set_fake_editor && |
234b3dae MH |
453 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \ |
454 | EXPECT_HEADER_COUNT=4 \ | |
455 | git rebase -i $base && | |
456 | test $base = $(git rev-parse HEAD^) && | |
457 | test 1 = $(git show | grep ONCE | wc -l) && | |
458 | git checkout to-be-rebased && | |
459 | git branch -D skip-comments | |
460 | ' | |
461 | ||
0d75bfe6 | 462 | test_expect_success C_LOCALE_OUTPUT 'squash ignores blank lines' ' |
234b3dae MH |
463 | git checkout -b skip-blank-lines E && |
464 | base=$(git rev-parse HEAD~4) && | |
31cd8275 | 465 | set_fake_editor && |
234b3dae MH |
466 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \ |
467 | EXPECT_HEADER_COUNT=4 \ | |
468 | git rebase -i $base && | |
469 | test $base = $(git rev-parse HEAD^) && | |
470 | test 1 = $(git show | grep ONCE | wc -l) && | |
471 | git checkout to-be-rebased && | |
472 | git branch -D skip-blank-lines | |
473 | ' | |
474 | ||
fb47cfbd | 475 | test_expect_success 'squash works as expected' ' |
6c4c44c4 | 476 | git checkout -b squash-works no-conflict-branch && |
fb47cfbd | 477 | one=$(git rev-parse HEAD~3) && |
31cd8275 | 478 | set_fake_editor && |
5065ed29 | 479 | FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \ |
959c0d06 | 480 | git rebase -i HEAD~3 && |
fb47cfbd JS |
481 | test $one = $(git rev-parse HEAD~2) |
482 | ' | |
483 | ||
484 | test_expect_success 'interrupted squash works as expected' ' | |
6c4c44c4 | 485 | git checkout -b interrupted-squash conflict-branch && |
fb47cfbd | 486 | one=$(git rev-parse HEAD~3) && |
31cd8275 | 487 | set_fake_editor && |
512477b1 | 488 | test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 && |
fb47cfbd JS |
489 | (echo one; echo two; echo four) > conflict && |
490 | git add conflict && | |
ab736792 | 491 | test_must_fail git rebase --continue && |
fb47cfbd JS |
492 | echo resolved > conflict && |
493 | git add conflict && | |
494 | git rebase --continue && | |
495 | test $one = $(git rev-parse HEAD~2) | |
496 | ' | |
497 | ||
1d25c8cf | 498 | test_expect_success 'interrupted squash works as expected (case 2)' ' |
6c4c44c4 | 499 | git checkout -b interrupted-squash2 conflict-branch && |
1d25c8cf | 500 | one=$(git rev-parse HEAD~3) && |
31cd8275 | 501 | set_fake_editor && |
512477b1 | 502 | test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 && |
1d25c8cf JS |
503 | (echo one; echo four) > conflict && |
504 | git add conflict && | |
ab736792 | 505 | test_must_fail git rebase --continue && |
1d25c8cf JS |
506 | (echo one; echo two; echo four) > conflict && |
507 | git add conflict && | |
ab736792 | 508 | test_must_fail git rebase --continue && |
1d25c8cf JS |
509 | echo resolved > conflict && |
510 | git add conflict && | |
511 | git rebase --continue && | |
512 | test $one = $(git rev-parse HEAD~2) | |
513 | ' | |
514 | ||
3f213981 | 515 | test_expect_success '--continue tries to commit, even for "edit"' ' |
96ffe892 JS |
516 | echo unrelated > file7 && |
517 | git add file7 && | |
518 | test_tick && | |
519 | git commit -m "unrelated change" && | |
be6ff208 JS |
520 | parent=$(git rev-parse HEAD^) && |
521 | test_tick && | |
31cd8275 | 522 | set_fake_editor && |
be6ff208 JS |
523 | FAKE_LINES="edit 1" git rebase -i HEAD^ && |
524 | echo edited > file7 && | |
525 | git add file7 && | |
526 | FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue && | |
527 | test edited = $(git show HEAD:file7) && | |
528 | git show HEAD | grep chouette && | |
529 | test $parent = $(git rev-parse HEAD^) | |
530 | ' | |
531 | ||
dc7f55cb SB |
532 | test_expect_success 'aborted --continue does not squash commits after "edit"' ' |
533 | old=$(git rev-parse HEAD) && | |
534 | test_tick && | |
31cd8275 | 535 | set_fake_editor && |
dc7f55cb SB |
536 | FAKE_LINES="edit 1" git rebase -i HEAD^ && |
537 | echo "edited again" > file7 && | |
538 | git add file7 && | |
512477b1 | 539 | test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue && |
dc7f55cb SB |
540 | test $old = $(git rev-parse HEAD) && |
541 | git rebase --abort | |
542 | ' | |
543 | ||
f8aa1b69 SB |
544 | test_expect_success 'auto-amend only edited commits after "edit"' ' |
545 | test_tick && | |
31cd8275 | 546 | set_fake_editor && |
f8aa1b69 SB |
547 | FAKE_LINES="edit 1" git rebase -i HEAD^ && |
548 | echo "edited again" > file7 && | |
549 | git add file7 && | |
550 | FAKE_COMMIT_MESSAGE="edited file7 again" git commit && | |
551 | echo "and again" > file7 && | |
552 | git add file7 && | |
553 | test_tick && | |
512477b1 | 554 | test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue && |
f8aa1b69 SB |
555 | git rebase --abort |
556 | ' | |
557 | ||
ffaaed88 MM |
558 | test_expect_success 'clean error after failed "exec"' ' |
559 | test_tick && | |
560 | test_when_finished "git rebase --abort || :" && | |
31cd8275 | 561 | set_fake_editor && |
512477b1 | 562 | test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ && |
ffaaed88 MM |
563 | echo "edited again" > file7 && |
564 | git add file7 && | |
565 | test_must_fail git rebase --continue 2>error && | |
18633e1a | 566 | test_i18ngrep "you have staged changes in your working tree" error |
ffaaed88 MM |
567 | ' |
568 | ||
73697a0b JS |
569 | test_expect_success 'rebase a detached HEAD' ' |
570 | grandparent=$(git rev-parse HEAD~2) && | |
571 | git checkout $(git rev-parse HEAD) && | |
572 | test_tick && | |
31cd8275 | 573 | set_fake_editor && |
73697a0b JS |
574 | FAKE_LINES="2 1" git rebase -i HEAD~2 && |
575 | test $grandparent = $(git rev-parse HEAD~2) | |
576 | ' | |
577 | ||
752527f5 JS |
578 | test_expect_success 'rebase a commit violating pre-commit' ' |
579 | ||
580 | mkdir -p .git/hooks && | |
7bec7f50 JH |
581 | write_script .git/hooks/pre-commit <<-\EOF && |
582 | test -z "$(git diff --cached --check)" | |
583 | EOF | |
752527f5 JS |
584 | echo "monde! " >> file1 && |
585 | test_tick && | |
ab736792 | 586 | test_must_fail git commit -m doesnt-verify file1 && |
752527f5 JS |
587 | git commit -m doesnt-verify --no-verify file1 && |
588 | test_tick && | |
31cd8275 | 589 | set_fake_editor && |
752527f5 JS |
590 | FAKE_LINES=2 git rebase -i HEAD~2 |
591 | ||
592 | ' | |
593 | ||
077b725f JH |
594 | test_expect_success 'rebase with a file named HEAD in worktree' ' |
595 | ||
596 | rm -fr .git/hooks && | |
597 | git reset --hard && | |
598 | git checkout -b branch3 A && | |
599 | ||
600 | ( | |
601 | GIT_AUTHOR_NAME="Squashed Away" && | |
602 | export GIT_AUTHOR_NAME && | |
603 | >HEAD && | |
604 | git add HEAD && | |
605 | git commit -m "Add head" && | |
606 | >BODY && | |
607 | git add BODY && | |
608 | git commit -m "Add body" | |
609 | ) && | |
610 | ||
31cd8275 | 611 | set_fake_editor && |
077b725f JH |
612 | FAKE_LINES="1 squash 2" git rebase -i to-be-rebased && |
613 | test "$(git show -s --pretty=format:%an)" = "Squashed Away" | |
614 | ||
615 | ' | |
616 | ||
ff74126c JS |
617 | test_expect_success 'do "noop" when there is nothing to cherry-pick' ' |
618 | ||
619 | git checkout -b branch4 HEAD && | |
620 | GIT_EDITOR=: git commit --amend \ | |
2dec68cf | 621 | --author="Somebody else <somebody@else.com>" && |
ff74126c | 622 | test $(git rev-parse branch3) != $(git rev-parse branch4) && |
31cd8275 | 623 | set_fake_editor && |
ff74126c JS |
624 | git rebase -i branch3 && |
625 | test $(git rev-parse branch3) = $(git rev-parse branch4) | |
626 | ||
627 | ' | |
628 | ||
96747696 JH |
629 | test_expect_success 'submodule rebase setup' ' |
630 | git checkout A && | |
631 | mkdir sub && | |
632 | ( | |
633 | cd sub && git init && >elif && | |
634 | git add elif && git commit -m "submodule initial" | |
635 | ) && | |
636 | echo 1 >file1 && | |
2dec68cf | 637 | git add file1 sub && |
96747696 JH |
638 | test_tick && |
639 | git commit -m "One" && | |
640 | echo 2 >file1 && | |
641 | test_tick && | |
642 | git commit -a -m "Two" && | |
643 | ( | |
644 | cd sub && echo 3 >elif && | |
645 | git commit -a -m "submodule second" | |
646 | ) && | |
647 | test_tick && | |
31cd8275 | 648 | set_fake_editor && |
96747696 JH |
649 | git commit -a -m "Three changes submodule" |
650 | ' | |
651 | ||
94c88ede | 652 | test_expect_success 'submodule rebase -i' ' |
31cd8275 | 653 | set_fake_editor && |
96747696 JH |
654 | FAKE_LINES="1 squash 2 3" git rebase -i A |
655 | ' | |
656 | ||
a6754cda JK |
657 | test_expect_success 'submodule conflict setup' ' |
658 | git tag submodule-base && | |
659 | git checkout HEAD^ && | |
660 | ( | |
661 | cd sub && git checkout HEAD^ && echo 4 >elif && | |
662 | git add elif && git commit -m "submodule conflict" | |
663 | ) && | |
664 | git add sub && | |
665 | test_tick && | |
666 | git commit -m "Conflict in submodule" && | |
667 | git tag submodule-topic | |
668 | ' | |
669 | ||
670 | test_expect_success 'rebase -i continue with only submodule staged' ' | |
31cd8275 | 671 | set_fake_editor && |
a6754cda JK |
672 | test_must_fail git rebase -i submodule-base && |
673 | git add sub && | |
674 | git rebase --continue && | |
675 | test $(git rev-parse submodule-base) != $(git rev-parse HEAD) | |
676 | ' | |
677 | ||
678 | test_expect_success 'rebase -i continue with unstaged submodule' ' | |
679 | git checkout submodule-topic && | |
680 | git reset --hard && | |
31cd8275 | 681 | set_fake_editor && |
a6754cda JK |
682 | test_must_fail git rebase -i submodule-base && |
683 | git reset && | |
684 | git rebase --continue && | |
685 | test $(git rev-parse submodule-base) = $(git rev-parse HEAD) | |
686 | ' | |
687 | ||
0e757e30 JS |
688 | test_expect_success 'avoid unnecessary reset' ' |
689 | git checkout master && | |
a6754cda | 690 | git reset --hard && |
0e757e30 JS |
691 | test-chmtime =123456789 file3 && |
692 | git update-index --refresh && | |
693 | HEAD=$(git rev-parse HEAD) && | |
31cd8275 | 694 | set_fake_editor && |
0e757e30 JS |
695 | git rebase -i HEAD~4 && |
696 | test $HEAD = $(git rev-parse HEAD) && | |
697 | MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') && | |
698 | test 123456789 = $MTIME | |
699 | ' | |
700 | ||
6741aa6c BG |
701 | test_expect_success 'reword' ' |
702 | git checkout -b reword-branch master && | |
31cd8275 | 703 | set_fake_editor && |
6741aa6c BG |
704 | FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A && |
705 | git show HEAD | grep "E changed" && | |
706 | test $(git rev-parse master) != $(git rev-parse HEAD) && | |
707 | test $(git rev-parse master^) = $(git rev-parse HEAD^) && | |
708 | FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A && | |
709 | git show HEAD^ | grep "D changed" && | |
710 | FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A && | |
711 | git show HEAD~3 | grep "B changed" && | |
712 | FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A && | |
713 | git show HEAD~2 | grep "C changed" | |
714 | ' | |
715 | ||
eb2151bb TR |
716 | test_expect_success 'rebase -i can copy notes' ' |
717 | git config notes.rewrite.rebase true && | |
718 | git config notes.rewriteRef "refs/notes/*" && | |
719 | test_commit n1 && | |
720 | test_commit n2 && | |
721 | test_commit n3 && | |
722 | git notes add -m"a note" n3 && | |
31cd8275 | 723 | set_fake_editor && |
6f87f038 | 724 | git rebase -i --onto n1 n2 && |
eb2151bb TR |
725 | test "a note" = "$(git notes show HEAD)" |
726 | ' | |
727 | ||
728 | cat >expect <<EOF | |
729 | an earlier note | |
d4990c4b | 730 | |
eb2151bb TR |
731 | a note |
732 | EOF | |
733 | ||
734 | test_expect_success 'rebase -i can copy notes over a fixup' ' | |
735 | git reset --hard n3 && | |
736 | git notes add -m"an earlier note" n2 && | |
31cd8275 | 737 | set_fake_editor && |
eb2151bb TR |
738 | GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 && |
739 | git notes show > output && | |
740 | test_cmp expect output | |
741 | ' | |
742 | ||
2ec33cdd DO |
743 | test_expect_success 'rebase while detaching HEAD' ' |
744 | git symbolic-ref HEAD && | |
745 | grandparent=$(git rev-parse HEAD~2) && | |
746 | test_tick && | |
31cd8275 | 747 | set_fake_editor && |
2ec33cdd DO |
748 | FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 && |
749 | test $grandparent = $(git rev-parse HEAD~2) && | |
750 | test_must_fail git symbolic-ref HEAD | |
751 | ' | |
752 | ||
b4995494 MB |
753 | test_tick # Ensure that the rebased commits get a different timestamp. |
754 | test_expect_success 'always cherry-pick with --no-ff' ' | |
755 | git checkout no-ff-branch && | |
756 | git tag original-no-ff-branch && | |
31cd8275 | 757 | set_fake_editor && |
b4995494 MB |
758 | git rebase -i --no-ff A && |
759 | touch empty && | |
760 | for p in 0 1 2 | |
761 | do | |
762 | test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) && | |
763 | git diff HEAD~$p original-no-ff-branch~$p > out && | |
764 | test_cmp empty out | |
765 | done && | |
766 | test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) && | |
767 | git diff HEAD~3 original-no-ff-branch~3 > out && | |
768 | test_cmp empty out | |
769 | ' | |
770 | ||
57f2b6b2 JH |
771 | test_expect_success 'set up commits with funny messages' ' |
772 | git checkout -b funny A && | |
773 | echo >>file1 && | |
774 | test_tick && | |
775 | git commit -a -m "end with slash\\" && | |
776 | echo >>file1 && | |
777 | test_tick && | |
938791cd BC |
778 | git commit -a -m "something (\000) that looks like octal" && |
779 | echo >>file1 && | |
780 | test_tick && | |
781 | git commit -a -m "something (\n) that looks like a newline" && | |
782 | echo >>file1 && | |
783 | test_tick && | |
57f2b6b2 JH |
784 | git commit -a -m "another commit" |
785 | ' | |
786 | ||
787 | test_expect_success 'rebase-i history with funny messages' ' | |
788 | git rev-list A..funny >expect && | |
789 | test_tick && | |
31cd8275 | 790 | set_fake_editor && |
938791cd | 791 | FAKE_LINES="1 2 3 4" git rebase -i A && |
57f2b6b2 JH |
792 | git rev-list A.. >actual && |
793 | test_cmp expect actual | |
794 | ' | |
795 | ||
c2145384 LK |
796 | test_expect_success 'prepare for rebase -i --exec' ' |
797 | git checkout master && | |
798 | git checkout -b execute && | |
799 | test_commit one_exec main.txt one_exec && | |
800 | test_commit two_exec main.txt two_exec && | |
801 | test_commit three_exec main.txt three_exec | |
802 | ' | |
803 | ||
c2145384 | 804 | test_expect_success 'running "git rebase -i --exec git show HEAD"' ' |
31cd8275 | 805 | set_fake_editor && |
c2145384 LK |
806 | git rebase -i --exec "git show HEAD" HEAD~2 >actual && |
807 | ( | |
808 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
809 | export FAKE_LINES && | |
810 | git rebase -i HEAD~2 >expect | |
811 | ) && | |
812 | sed -e "1,9d" expect >expected && | |
813 | test_cmp expected actual | |
814 | ' | |
815 | ||
c2145384 LK |
816 | test_expect_success 'running "git rebase --exec git show HEAD -i"' ' |
817 | git reset --hard execute && | |
31cd8275 | 818 | set_fake_editor && |
c2145384 LK |
819 | git rebase --exec "git show HEAD" -i HEAD~2 >actual && |
820 | ( | |
821 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
822 | export FAKE_LINES && | |
823 | git rebase -i HEAD~2 >expect | |
824 | ) && | |
825 | sed -e "1,9d" expect >expected && | |
826 | test_cmp expected actual | |
827 | ' | |
828 | ||
c2145384 LK |
829 | test_expect_success 'running "git rebase -ix git show HEAD"' ' |
830 | git reset --hard execute && | |
31cd8275 | 831 | set_fake_editor && |
c2145384 LK |
832 | git rebase -ix "git show HEAD" HEAD~2 >actual && |
833 | ( | |
834 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
835 | export FAKE_LINES && | |
836 | git rebase -i HEAD~2 >expect | |
837 | ) && | |
838 | sed -e "1,9d" expect >expected && | |
839 | test_cmp expected actual | |
840 | ' | |
841 | ||
842 | ||
843 | test_expect_success 'rebase -ix with several <CMD>' ' | |
844 | git reset --hard execute && | |
31cd8275 | 845 | set_fake_editor && |
c2145384 LK |
846 | git rebase -ix "git show HEAD; pwd" HEAD~2 >actual && |
847 | ( | |
848 | FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" && | |
849 | export FAKE_LINES && | |
850 | git rebase -i HEAD~2 >expect | |
851 | ) && | |
852 | sed -e "1,9d" expect >expected && | |
853 | test_cmp expected actual | |
854 | ' | |
855 | ||
c2145384 LK |
856 | test_expect_success 'rebase -ix with several instances of --exec' ' |
857 | git reset --hard execute && | |
31cd8275 | 858 | set_fake_editor && |
c2145384 LK |
859 | git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual && |
860 | ( | |
861 | FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2 | |
862 | exec_git_show_HEAD exec_pwd" && | |
863 | export FAKE_LINES && | |
864 | git rebase -i HEAD~2 >expect | |
865 | ) && | |
866 | sed -e "1,11d" expect >expected && | |
867 | test_cmp expected actual | |
868 | ' | |
869 | ||
0d75bfe6 | 870 | test_expect_success C_LOCALE_OUTPUT 'rebase -ix with --autosquash' ' |
c2145384 LK |
871 | git reset --hard execute && |
872 | git checkout -b autosquash && | |
873 | echo second >second.txt && | |
874 | git add second.txt && | |
875 | git commit -m "fixup! two_exec" && | |
876 | echo bis >bis.txt && | |
877 | git add bis.txt && | |
878 | git commit -m "fixup! two_exec" && | |
31cd8275 | 879 | set_fake_editor && |
c2145384 LK |
880 | ( |
881 | git checkout -b autosquash_actual && | |
882 | git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual | |
883 | ) && | |
884 | git checkout autosquash && | |
885 | ( | |
886 | git checkout -b autosquash_expected && | |
887 | FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
888 | export FAKE_LINES && | |
889 | git rebase -i HEAD~4 >expect | |
890 | ) && | |
891 | sed -e "1,13d" expect >expected && | |
892 | test_cmp expected actual | |
893 | ' | |
894 | ||
78ec2400 | 895 | test_expect_success 'rebase --exec works without -i ' ' |
c2145384 | 896 | git reset --hard execute && |
78ec2400 SB |
897 | rm -rf exec_output && |
898 | EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual && | |
899 | test_i18ngrep "Successfully rebased and updated" actual && | |
900 | test_line_count = 2 exec_output && | |
901 | test_path_is_missing invoked_editor | |
c2145384 LK |
902 | ' |
903 | ||
c2145384 LK |
904 | test_expect_success 'rebase -i --exec without <CMD>' ' |
905 | git reset --hard execute && | |
31cd8275 | 906 | set_fake_editor && |
c2145384 LK |
907 | test_must_fail git rebase -i --exec 2>tmp && |
908 | sed -e "1d" tmp >actual && | |
909 | test_must_fail git rebase -h >expected && | |
910 | test_cmp expected actual && | |
911 | git checkout master | |
912 | ' | |
913 | ||
b64b7feb CW |
914 | test_expect_success 'rebase -i --root re-order and drop commits' ' |
915 | git checkout E && | |
31cd8275 | 916 | set_fake_editor && |
b64b7feb CW |
917 | FAKE_LINES="3 1 2 5" git rebase -i --root && |
918 | test E = $(git cat-file commit HEAD | sed -ne \$p) && | |
919 | test B = $(git cat-file commit HEAD^ | sed -ne \$p) && | |
920 | test A = $(git cat-file commit HEAD^^ | sed -ne \$p) && | |
921 | test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) && | |
922 | test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ ) | |
923 | ' | |
924 | ||
925 | test_expect_success 'rebase -i --root retain root commit author and message' ' | |
926 | git checkout A && | |
927 | echo B >file7 && | |
928 | git add file7 && | |
929 | GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && | |
31cd8275 | 930 | set_fake_editor && |
b64b7feb CW |
931 | FAKE_LINES="2" git rebase -i --root && |
932 | git cat-file commit HEAD | grep -q "^author Twerp Snog" && | |
933 | git cat-file commit HEAD | grep -q "^different author$" | |
934 | ' | |
935 | ||
936 | test_expect_success 'rebase -i --root temporary sentinel commit' ' | |
937 | git checkout B && | |
512477b1 DT |
938 | set_fake_editor && |
939 | test_must_fail env FAKE_LINES="2" git rebase -i --root && | |
b64b7feb CW |
940 | git cat-file commit HEAD | grep "^tree 4b825dc642cb" && |
941 | git rebase --abort | |
942 | ' | |
943 | ||
2147f844 CW |
944 | test_expect_success 'rebase -i --root fixup root commit' ' |
945 | git checkout B && | |
31cd8275 | 946 | set_fake_editor && |
2147f844 CW |
947 | FAKE_LINES="1 fixup 2" git rebase -i --root && |
948 | test A = $(git cat-file commit HEAD | sed -ne \$p) && | |
949 | test B = $(git show HEAD:file1) && | |
950 | test 0 = $(git cat-file commit HEAD | grep -c ^parent\ ) | |
951 | ' | |
952 | ||
0d75bfe6 | 953 | test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' ' |
9f4981ba AW |
954 | git reset --hard && |
955 | git checkout conflict-branch && | |
31cd8275 | 956 | set_fake_editor && |
9f4981ba AW |
957 | test_must_fail git rebase --onto HEAD~2 HEAD~ && |
958 | test_must_fail git rebase --edit-todo && | |
959 | git rebase --abort | |
960 | ' | |
961 | ||
962 | test_expect_success 'rebase --edit-todo can be used to modify todo' ' | |
963 | git reset --hard && | |
964 | git checkout no-conflict-branch^0 && | |
31cd8275 | 965 | set_fake_editor && |
9f4981ba AW |
966 | FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 && |
967 | FAKE_LINES="2 1" git rebase --edit-todo && | |
60687de5 | 968 | git rebase --continue && |
9f4981ba AW |
969 | test M = $(git cat-file commit HEAD^ | sed -ne \$p) && |
970 | test L = $(git cat-file commit HEAD | sed -ne \$p) | |
971 | ' | |
972 | ||
26cd160c RR |
973 | test_expect_success 'rebase -i produces readable reflog' ' |
974 | git reset --hard && | |
975 | git branch -f branch-reflog-test H && | |
31cd8275 | 976 | set_fake_editor && |
26cd160c RR |
977 | git rebase -i --onto I F branch-reflog-test && |
978 | cat >expect <<-\EOF && | |
26cd160c | 979 | rebase -i (finish): returning to refs/heads/branch-reflog-test |
d0ab0584 DT |
980 | rebase -i (pick): H |
981 | rebase -i (pick): G | |
982 | rebase -i (start): checkout I | |
26cd160c | 983 | EOF |
d0ab0584 DT |
984 | git reflog -n4 HEAD | |
985 | sed "s/[^:]*: //" >actual && | |
26cd160c RR |
986 | test_cmp expect actual |
987 | ' | |
988 | ||
180bad3d JK |
989 | test_expect_success 'rebase -i respects core.commentchar' ' |
990 | git reset --hard && | |
991 | git checkout E^0 && | |
aac6c2f4 | 992 | test_config core.commentchar "\\" && |
180bad3d JK |
993 | write_script remove-all-but-first.sh <<-\EOF && |
994 | sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" && | |
995 | mv "$1.tmp" "$1" | |
996 | EOF | |
997 | test_set_editor "$(pwd)/remove-all-but-first.sh" && | |
998 | git rebase -i B && | |
999 | test B = $(git cat-file commit HEAD^ | sed -ne \$p) | |
1000 | ' | |
1001 | ||
882cd237 | 1002 | test_expect_success 'rebase -i respects core.commentchar=auto' ' |
66458388 JS |
1003 | test_config core.commentchar auto && |
1004 | write_script copy-edit-script.sh <<-\EOF && | |
1005 | cp "$1" edit-script | |
1006 | EOF | |
1007 | test_set_editor "$(pwd)/copy-edit-script.sh" && | |
1008 | test_when_finished "git rebase --abort || :" && | |
1009 | git rebase -i HEAD^ && | |
1010 | test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)" | |
1011 | ' | |
1012 | ||
2e6e276d | 1013 | test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' ' |
6567dc05 RR |
1014 | test_when_finished "git branch -D torebase" && |
1015 | git checkout -b torebase branch1 && | |
1016 | upstream=$(git rev-parse ":/J") && | |
1017 | onto=$(git rev-parse ":/A") && | |
1018 | git rebase --onto $onto $upstream && | |
1019 | git reset --hard branch1 && | |
1020 | git rebase --onto ":/A" ":/J" && | |
1021 | git checkout branch1 | |
1022 | ' | |
1023 | ||
db2b3b82 AF |
1024 | test_expect_success 'rebase -i with --strategy and -X' ' |
1025 | git checkout -b conflict-merge-use-theirs conflict-branch && | |
1026 | git reset --hard HEAD^ && | |
1027 | echo five >conflict && | |
1028 | echo Z >file1 && | |
1029 | git commit -a -m "one file conflict" && | |
1030 | EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch && | |
1031 | test $(git show conflict-branch:conflict) = $(cat conflict) && | |
1032 | test $(cat file1) = Z | |
1033 | ' | |
1034 | ||
040fd39e FR |
1035 | test_expect_success 'interrupted rebase -i with --strategy and -X' ' |
1036 | git checkout -b conflict-merge-use-theirs-interrupted conflict-branch && | |
1037 | git reset --hard HEAD^ && | |
1038 | >breakpoint && | |
1039 | git add breakpoint && | |
1040 | git commit -m "breakpoint for interactive mode" && | |
1041 | echo five >conflict && | |
1042 | echo Z >file1 && | |
1043 | git commit -a -m "one file conflict" && | |
1044 | set_fake_editor && | |
1045 | FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive -Xours conflict-branch && | |
1046 | git rebase --continue && | |
1047 | test $(git show conflict-branch:conflict) = $(cat conflict) && | |
1048 | test $(cat file1) = Z | |
1049 | ' | |
1050 | ||
89b0230a | 1051 | test_expect_success 'rebase -i error on commits with \ in message' ' |
99094a7a | 1052 | current_head=$(git rev-parse HEAD) && |
89b0230a MM |
1053 | test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" && |
1054 | test_commit TO-REMOVE will-conflict old-content && | |
1055 | test_commit "\temp" will-conflict new-content dummy && | |
512477b1 | 1056 | test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error && |
89b0230a MM |
1057 | test_expect_code 1 grep " emp" error |
1058 | ' | |
1059 | ||
66ae9a57 ES |
1060 | test_expect_success 'short SHA-1 setup' ' |
1061 | test_when_finished "git checkout master" && | |
1062 | git checkout --orphan collide && | |
1063 | git rm -rf . && | |
1064 | ( | |
1065 | unset test_tick && | |
1066 | test_commit collide1 collide && | |
1067 | test_commit --notick collide2 collide && | |
1068 | test_commit --notick collide3 collide | |
1069 | ) | |
1070 | ' | |
1071 | ||
75c69766 | 1072 | test_expect_success 'short SHA-1 collide' ' |
66ae9a57 ES |
1073 | test_when_finished "reset_rebase && git checkout master" && |
1074 | git checkout collide && | |
1075 | ( | |
1076 | unset test_tick && | |
1077 | test_tick && | |
1078 | set_fake_editor && | |
1079 | FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \ | |
1080 | FAKE_LINES="reword 1 2" git rebase -i HEAD~2 | |
1081 | ) | |
1082 | ' | |
1083 | ||
edb72d55 KS |
1084 | test_expect_success 'respect core.abbrev' ' |
1085 | git config core.abbrev 12 && | |
1086 | set_cat_todo_editor && | |
1087 | test_must_fail git rebase -i HEAD~4 >todo-list && | |
1088 | test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list) | |
1089 | ' | |
1090 | ||
28c8cfc3 ES |
1091 | test_expect_success 'todo count' ' |
1092 | write_script dump-raw.sh <<-\EOF && | |
1093 | cat "$1" | |
1094 | EOF | |
1095 | test_set_editor "$(pwd)/dump-raw.sh" && | |
1096 | git rebase -i HEAD~4 >actual && | |
b8fc9e43 | 1097 | test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual |
28c8cfc3 ES |
1098 | ' |
1099 | ||
8cbc57ca PH |
1100 | test_expect_success 'rebase -i commits that overwrite untracked files (pick)' ' |
1101 | git checkout --force branch2 && | |
1102 | git clean -f && | |
1103 | set_fake_editor && | |
1104 | FAKE_LINES="edit 1 2" git rebase -i A && | |
1105 | test_cmp_rev HEAD F && | |
1106 | test_path_is_missing file6 && | |
1107 | >file6 && | |
1108 | test_must_fail git rebase --continue && | |
1109 | test_cmp_rev HEAD F && | |
1110 | rm file6 && | |
1111 | git rebase --continue && | |
1112 | test_cmp_rev HEAD I | |
1113 | ' | |
1114 | ||
1115 | test_expect_success 'rebase -i commits that overwrite untracked files (squash)' ' | |
1116 | git checkout --force branch2 && | |
1117 | git clean -f && | |
1118 | git tag original-branch2 && | |
1119 | set_fake_editor && | |
1120 | FAKE_LINES="edit 1 squash 2" git rebase -i A && | |
1121 | test_cmp_rev HEAD F && | |
1122 | test_path_is_missing file6 && | |
1123 | >file6 && | |
1124 | test_must_fail git rebase --continue && | |
1125 | test_cmp_rev HEAD F && | |
1126 | rm file6 && | |
1127 | git rebase --continue && | |
1128 | test $(git cat-file commit HEAD | sed -ne \$p) = I && | |
1129 | git reset --hard original-branch2 | |
1130 | ' | |
1131 | ||
1132 | test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' ' | |
1133 | git checkout --force branch2 && | |
1134 | git clean -f && | |
1135 | set_fake_editor && | |
1136 | FAKE_LINES="edit 1 2" git rebase -i --no-ff A && | |
1137 | test $(git cat-file commit HEAD | sed -ne \$p) = F && | |
1138 | test_path_is_missing file6 && | |
1139 | >file6 && | |
1140 | test_must_fail git rebase --continue && | |
1141 | test $(git cat-file commit HEAD | sed -ne \$p) = F && | |
1142 | rm file6 && | |
1143 | git rebase --continue && | |
1144 | test $(git cat-file commit HEAD | sed -ne \$p) = I | |
1145 | ' | |
1146 | ||
0e0aff4b | 1147 | test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' ' |
d17ec3a9 JS |
1148 | git checkout -b commit-to-skip && |
1149 | for double in X 3 1 | |
1150 | do | |
1151 | test_seq 5 | sed "s/$double/&&/" >seq && | |
1152 | git add seq && | |
1153 | test_tick && | |
1154 | git commit -m seq-$double | |
1155 | done && | |
1156 | git tag seq-onto && | |
1157 | git reset --hard HEAD~2 && | |
1158 | git cherry-pick seq-onto && | |
1159 | set_fake_editor && | |
1160 | test_must_fail env FAKE_LINES= git rebase -i seq-onto && | |
1161 | test -d .git/rebase-merge && | |
1162 | git rebase --continue && | |
1163 | git diff --exit-code seq-onto && | |
1164 | test ! -d .git/rebase-merge && | |
1165 | test ! -f .git/CHERRY_PICK_HEAD | |
1166 | ' | |
1167 | ||
c9266d58 GR |
1168 | rebase_setup_and_clean () { |
1169 | test_when_finished " | |
1170 | git checkout master && | |
1171 | test_might_fail git branch -D $1 && | |
1172 | test_might_fail git rebase --abort | |
1173 | " && | |
1174 | git checkout -b $1 master | |
1175 | } | |
1176 | ||
1177 | test_expect_success 'drop' ' | |
1178 | rebase_setup_and_clean drop-test && | |
1179 | set_fake_editor && | |
1180 | FAKE_LINES="1 drop 2 3 drop 4 5" git rebase -i --root && | |
1181 | test E = $(git cat-file commit HEAD | sed -ne \$p) && | |
1182 | test C = $(git cat-file commit HEAD^ | sed -ne \$p) && | |
1183 | test A = $(git cat-file commit HEAD^^ | sed -ne \$p) | |
1184 | ' | |
1185 | ||
37079959 GR |
1186 | cat >expect <<EOF |
1187 | Successfully rebased and updated refs/heads/missing-commit. | |
1188 | EOF | |
1189 | ||
1190 | test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' ' | |
1191 | test_config rebase.missingCommitsCheck ignore && | |
1192 | rebase_setup_and_clean missing-commit && | |
1193 | set_fake_editor && | |
1194 | FAKE_LINES="1 2 3 4" \ | |
1195 | git rebase -i --root 2>actual && | |
1196 | test D = $(git cat-file commit HEAD | sed -ne \$p) && | |
b8fc9e43 | 1197 | test_i18ncmp expect actual |
37079959 GR |
1198 | ' |
1199 | ||
1200 | cat >expect <<EOF | |
1201 | Warning: some commits may have been dropped accidentally. | |
1202 | Dropped commits (newer to older): | |
1203 | - $(git rev-list --pretty=oneline --abbrev-commit -1 master) | |
1204 | To avoid this message, use "drop" to explicitly remove a commit. | |
1205 | ||
1206 | Use 'git config rebase.missingCommitsCheck' to change the level of warnings. | |
1207 | The possible behaviours are: ignore, warn, error. | |
1208 | ||
1209 | Successfully rebased and updated refs/heads/missing-commit. | |
1210 | EOF | |
1211 | ||
1212 | test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' ' | |
1213 | test_config rebase.missingCommitsCheck warn && | |
1214 | rebase_setup_and_clean missing-commit && | |
1215 | set_fake_editor && | |
1216 | FAKE_LINES="1 2 3 4" \ | |
1217 | git rebase -i --root 2>actual && | |
b8fc9e43 | 1218 | test_i18ncmp expect actual && |
37079959 GR |
1219 | test D = $(git cat-file commit HEAD | sed -ne \$p) |
1220 | ' | |
1221 | ||
1222 | cat >expect <<EOF | |
1223 | Warning: some commits may have been dropped accidentally. | |
1224 | Dropped commits (newer to older): | |
1225 | - $(git rev-list --pretty=oneline --abbrev-commit -1 master) | |
1226 | - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2) | |
1227 | To avoid this message, use "drop" to explicitly remove a commit. | |
1228 | ||
1229 | Use 'git config rebase.missingCommitsCheck' to change the level of warnings. | |
1230 | The possible behaviours are: ignore, warn, error. | |
1231 | ||
37875b47 | 1232 | You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'. |
37079959 GR |
1233 | Or you can abort the rebase with 'git rebase --abort'. |
1234 | EOF | |
1235 | ||
1236 | test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' | |
1237 | test_config rebase.missingCommitsCheck error && | |
1238 | rebase_setup_and_clean missing-commit && | |
1239 | set_fake_editor && | |
1240 | test_must_fail env FAKE_LINES="1 2 4" \ | |
1241 | git rebase -i --root 2>actual && | |
b8fc9e43 | 1242 | test_i18ncmp expect actual && |
37079959 GR |
1243 | cp .git/rebase-merge/git-rebase-todo.backup \ |
1244 | .git/rebase-merge/git-rebase-todo && | |
1245 | FAKE_LINES="1 2 drop 3 4 drop 5" \ | |
1246 | git rebase --edit-todo && | |
1247 | git rebase --continue && | |
1248 | test D = $(git cat-file commit HEAD | sed -ne \$p) && | |
1249 | test B = $(git cat-file commit HEAD^ | sed -ne \$p) | |
1250 | ' | |
1251 | ||
804098bb GR |
1252 | cat >expect <<EOF |
1253 | Warning: the command isn't recognized in the following line: | |
1254 | - badcmd $(git rev-list --oneline -1 master~1) | |
1255 | ||
37875b47 | 1256 | You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'. |
804098bb GR |
1257 | Or you can abort the rebase with 'git rebase --abort'. |
1258 | EOF | |
1259 | ||
1260 | test_expect_success 'static check of bad command' ' | |
1261 | rebase_setup_and_clean bad-cmd && | |
1262 | set_fake_editor && | |
1263 | test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \ | |
1264 | git rebase -i --root 2>actual && | |
b8fc9e43 | 1265 | test_i18ncmp expect actual && |
804098bb GR |
1266 | FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo && |
1267 | git rebase --continue && | |
1268 | test E = $(git cat-file commit HEAD | sed -ne \$p) && | |
1269 | test C = $(git cat-file commit HEAD^ | sed -ne \$p) | |
1270 | ' | |
1271 | ||
1db168ee MM |
1272 | test_expect_success 'tabs and spaces are accepted in the todolist' ' |
1273 | rebase_setup_and_clean indented-comment && | |
1274 | write_script add-indent.sh <<-\EOF && | |
1275 | ( | |
1276 | # Turn single spaces into space/tab mix | |
1277 | sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1" | |
1278 | printf "\n\t# comment\n #more\n\t # comment\n" | |
7966230b | 1279 | ) >"$1.new" |
1db168ee MM |
1280 | mv "$1.new" "$1" |
1281 | EOF | |
1282 | test_set_editor "$(pwd)/add-indent.sh" && | |
1283 | git rebase -i HEAD^^^ && | |
1284 | test E = $(git cat-file commit HEAD | sed -ne \$p) | |
1285 | ' | |
1286 | ||
804098bb GR |
1287 | cat >expect <<EOF |
1288 | Warning: the SHA-1 is missing or isn't a commit in the following line: | |
1289 | - edit XXXXXXX False commit | |
1290 | ||
37875b47 | 1291 | You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'. |
804098bb GR |
1292 | Or you can abort the rebase with 'git rebase --abort'. |
1293 | EOF | |
1294 | ||
1295 | test_expect_success 'static check of bad SHA-1' ' | |
1296 | rebase_setup_and_clean bad-sha && | |
1297 | set_fake_editor && | |
1298 | test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \ | |
1299 | git rebase -i --root 2>actual && | |
b8fc9e43 | 1300 | test_i18ncmp expect actual && |
804098bb GR |
1301 | FAKE_LINES="1 2 4 5 6" git rebase --edit-todo && |
1302 | git rebase --continue && | |
1303 | test E = $(git cat-file commit HEAD | sed -ne \$p) | |
1304 | ' | |
1305 | ||
39743cf5 | 1306 | test_expect_success 'editor saves as CR/LF' ' |
1db25aae JS |
1307 | git checkout -b with-crlf && |
1308 | write_script add-crs.sh <<-\EOF && | |
1309 | sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new && | |
1310 | mv -f "$1".new "$1" | |
1311 | EOF | |
1312 | ( | |
1313 | test_set_editor "$(pwd)/add-crs.sh" && | |
1314 | git rebase -i HEAD^ | |
1315 | ) | |
1316 | ' | |
1317 | ||
6672b9f9 JS |
1318 | SQ="'" |
1319 | test_expect_success 'rebase -i --gpg-sign=<key-id>' ' | |
1320 | set_fake_editor && | |
1321 | FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \ | |
1322 | >out 2>err && | |
7ca79dca | 1323 | test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err |
6672b9f9 JS |
1324 | ' |
1325 | ||
1b1dce4b | 1326 | test_done |