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