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