]>
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 | |
1b1dce4b | 32 | test_expect_success 'setup' ' |
163f3925 MH |
33 | test_commit A file1 && |
34 | test_commit B file1 && | |
35 | test_commit C file2 && | |
36 | test_commit D file1 && | |
37 | test_commit E file3 && | |
1b1dce4b | 38 | git checkout -b branch1 A && |
163f3925 MH |
39 | test_commit F file4 && |
40 | test_commit G file1 && | |
41 | test_commit H file5 && | |
1b1dce4b | 42 | git checkout -b branch2 F && |
2dec68cf | 43 | test_commit I file6 && |
6c4c44c4 | 44 | git checkout -b conflict-branch A && |
391a825f JN |
45 | test_commit one conflict && |
46 | test_commit two conflict && | |
47 | test_commit three conflict && | |
48 | test_commit four conflict && | |
6c4c44c4 | 49 | git checkout -b no-conflict-branch A && |
391a825f JN |
50 | test_commit J fileJ && |
51 | test_commit K fileK && | |
52 | test_commit L fileL && | |
53 | test_commit M fileM && | |
b4995494 | 54 | git checkout -b no-ff-branch A && |
391a825f JN |
55 | test_commit N fileN && |
56 | test_commit O fileO && | |
57 | test_commit P fileP | |
1b1dce4b JS |
58 | ' |
59 | ||
fa90ab4a | 60 | # "exec" commands are run with the user shell by default, but this may |
cd035b1c | 61 | # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work |
386aad5a | 62 | # to create a file. Unsetting SHELL avoids such non-portable behavior |
5cd3e107 | 63 | # in tests. It must be exported for it to take effect where needed. |
cd035b1c | 64 | SHELL= |
5cd3e107 | 65 | export SHELL |
cd035b1c | 66 | |
bd46cfae MT |
67 | test_expect_success 'rebase --keep-empty' ' |
68 | git checkout -b emptybranch master && | |
69 | git commit --allow-empty -m "empty" && | |
70 | git rebase --keep-empty -i HEAD~2 && | |
71 | git log --oneline >actual && | |
72 | test_line_count = 6 actual | |
73 | ' | |
74 | ||
a9ae8fde | 75 | test_expect_success 'rebase -i with empty todo list' ' |
c9749b36 SG |
76 | cat >expect <<-\EOF && |
77 | error: nothing to do | |
78 | EOF | |
b2dbacbd PW |
79 | ( |
80 | set_fake_editor && | |
a9ae8fde EN |
81 | test_must_fail env FAKE_LINES="#" \ |
82 | git rebase -i HEAD^ >output 2>&1 | |
b2dbacbd | 83 | ) && |
a9ae8fde | 84 | tail -n 1 output >actual && # Ignore output about changing todo list |
d078c391 AG |
85 | test_i18ncmp expect actual |
86 | ' | |
87 | ||
cd035b1c MM |
88 | test_expect_success 'rebase -i with the exec command' ' |
89 | git checkout master && | |
90 | ( | |
31cd8275 | 91 | set_fake_editor && |
cd035b1c MM |
92 | FAKE_LINES="1 exec_>touch-one |
93 | 2 exec_>touch-two exec_false exec_>touch-three | |
94 | 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" && | |
95 | export FAKE_LINES && | |
96 | test_must_fail git rebase -i A | |
97 | ) && | |
2caf20c5 MM |
98 | test_path_is_file touch-one && |
99 | test_path_is_file touch-two && | |
100 | test_path_is_missing touch-three " (should have stopped before)" && | |
5c947e2c | 101 | test_cmp_rev C HEAD && |
cd035b1c | 102 | git rebase --continue && |
2caf20c5 MM |
103 | test_path_is_file touch-three && |
104 | test_path_is_file "touch-file name with spaces" && | |
105 | test_path_is_file touch-after-semicolon && | |
5c947e2c | 106 | test_cmp_rev master HEAD && |
cd035b1c MM |
107 | rm -f touch-* |
108 | ' | |
109 | ||
110 | test_expect_success 'rebase -i with the exec command runs from tree root' ' | |
111 | git checkout master && | |
c2e0940b | 112 | mkdir subdir && (cd subdir && |
31cd8275 | 113 | set_fake_editor && |
cd035b1c | 114 | FAKE_LINES="1 exec_>touch-subdir" \ |
c2e0940b JL |
115 | git rebase -i HEAD^ |
116 | ) && | |
2caf20c5 | 117 | test_path_is_file touch-subdir && |
cd035b1c MM |
118 | rm -fr subdir |
119 | ' | |
120 | ||
09d7b6c6 JK |
121 | test_expect_success 'rebase -i with exec allows git commands in subdirs' ' |
122 | test_when_finished "rm -rf subdir" && | |
123 | test_when_finished "git rebase --abort ||:" && | |
124 | git checkout master && | |
125 | mkdir subdir && (cd subdir && | |
126 | set_fake_editor && | |
8c64bc94 | 127 | FAKE_LINES="1 x_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \ |
09d7b6c6 JK |
128 | git rebase -i HEAD^ |
129 | ) | |
130 | ' | |
131 | ||
ab5e67d7 | 132 | test_expect_success 'rebase -i sets work tree properly' ' |
133 | test_when_finished "rm -rf subdir" && | |
134 | test_when_finished "test_might_fail git rebase --abort" && | |
135 | mkdir subdir && | |
136 | git rebase -x "(cd subdir && git rev-parse --show-toplevel)" HEAD^ \ | |
137 | >actual && | |
138 | ! grep "/subdir$" actual | |
139 | ' | |
140 | ||
cd035b1c MM |
141 | test_expect_success 'rebase -i with the exec command checks tree cleanness' ' |
142 | git checkout master && | |
b2dbacbd PW |
143 | ( |
144 | set_fake_editor && | |
145 | test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" \ | |
146 | git rebase -i HEAD^ | |
147 | ) && | |
5c947e2c | 148 | test_cmp_rev master^ HEAD && |
cd035b1c MM |
149 | git reset --hard && |
150 | git rebase --continue | |
151 | ' | |
152 | ||
c762aada PW |
153 | test_expect_success 'rebase -x with empty command fails' ' |
154 | test_when_finished "git rebase --abort ||:" && | |
d03ebd41 | 155 | test_must_fail env git rebase -x "" @ 2>actual && |
c762aada PW |
156 | test_write_lines "error: empty exec command" >expected && |
157 | test_i18ncmp expected actual && | |
d03ebd41 | 158 | test_must_fail env git rebase -x " " @ 2>actual && |
c762aada PW |
159 | test_i18ncmp expected actual |
160 | ' | |
161 | ||
c762aada PW |
162 | test_expect_success 'rebase -x with newline in command fails' ' |
163 | test_when_finished "git rebase --abort ||:" && | |
d03ebd41 | 164 | test_must_fail env git rebase -x "a${LF}b" @ 2>actual && |
c762aada PW |
165 | test_write_lines "error: exec commands cannot contain newlines" \ |
166 | >expected && | |
167 | test_i18ncmp expected actual | |
168 | ' | |
169 | ||
ecfe1ea9 JS |
170 | test_expect_success 'rebase -i with exec of inexistent command' ' |
171 | git checkout master && | |
172 | test_when_finished "git rebase --abort" && | |
b2dbacbd PW |
173 | ( |
174 | set_fake_editor && | |
175 | test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \ | |
176 | git rebase -i HEAD^ >actual 2>&1 | |
177 | ) && | |
ecfe1ea9 JS |
178 | ! grep "Maybe git-rebase is broken" actual |
179 | ' | |
180 | ||
891d4a03 PW |
181 | test_expect_success 'implicit interactive rebase does not invoke sequence editor' ' |
182 | test_when_finished "git rebase --abort ||:" && | |
183 | GIT_SEQUENCE_EDITOR="echo bad >" git rebase -x"echo one" @^ | |
184 | ' | |
185 | ||
1b1dce4b | 186 | test_expect_success 'no changes are a nop' ' |
6c4c44c4 | 187 | git checkout branch2 && |
1b1dce4b | 188 | git rebase -i F && |
ab736792 | 189 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && |
780308d0 | 190 | test_cmp_rev I HEAD |
1b1dce4b JS |
191 | ' |
192 | ||
c9e65892 JS |
193 | test_expect_success 'test the [branch] option' ' |
194 | git checkout -b dead-end && | |
195 | git rm file6 && | |
196 | git commit -m "stop here" && | |
197 | git rebase -i F branch2 && | |
ab736792 | 198 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && |
780308d0 PW |
199 | test_cmp_rev I branch2 && |
200 | test_cmp_rev I HEAD | |
c9e65892 JS |
201 | ' |
202 | ||
ab736792 SB |
203 | test_expect_success 'test --onto <branch>' ' |
204 | git checkout -b test-onto branch2 && | |
205 | git rebase -i --onto branch1 F && | |
206 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" && | |
780308d0 PW |
207 | test_cmp_rev HEAD^ branch1 && |
208 | test_cmp_rev I branch2 | |
ab736792 SB |
209 | ' |
210 | ||
1b1dce4b JS |
211 | test_expect_success 'rebase on top of a non-conflicting commit' ' |
212 | git checkout branch1 && | |
213 | git tag original-branch1 && | |
214 | git rebase -i branch2 && | |
215 | test file6 = $(git diff --name-only original-branch1) && | |
ab736792 | 216 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" && |
780308d0 PW |
217 | test_cmp_rev I branch2 && |
218 | test_cmp_rev I HEAD~2 | |
1b1dce4b JS |
219 | ' |
220 | ||
68a163c9 | 221 | test_expect_success 'reflog for the branch shows state before rebase' ' |
780308d0 | 222 | test_cmp_rev branch1@{1} original-branch1 |
68a163c9 JS |
223 | ' |
224 | ||
1ceb9dfa | 225 | test_expect_success 'reflog for the branch shows correct finish message' ' |
c2417d3a | 226 | printf "rebase (finish): refs/heads/branch1 onto %s\n" \ |
1ceb9dfa PW |
227 | "$(git rev-parse branch2)" >expected && |
228 | git log -g --pretty=%gs -1 refs/heads/branch1 >actual && | |
229 | test_cmp expected actual | |
230 | ' | |
231 | ||
1b1dce4b | 232 | test_expect_success 'exchange two commits' ' |
b2dbacbd PW |
233 | ( |
234 | set_fake_editor && | |
235 | FAKE_LINES="2 1" git rebase -i HEAD~2 | |
236 | ) && | |
b4ce54fc | 237 | test H = $(git cat-file commit HEAD^ | sed -ne \$p) && |
4dd1b5f9 | 238 | test G = $(git cat-file commit HEAD | sed -ne \$p) && |
239 | blob1=$(git rev-parse --short HEAD^:file1) && | |
240 | blob2=$(git rev-parse --short HEAD:file1) && | |
241 | commit=$(git rev-parse --short HEAD) | |
1b1dce4b JS |
242 | ' |
243 | ||
1b1dce4b | 244 | test_expect_success 'stop on conflicting pick' ' |
4dd1b5f9 | 245 | cat >expect <<-EOF && |
c9749b36 | 246 | diff --git a/file1 b/file1 |
4dd1b5f9 | 247 | index $blob1..$blob2 100644 |
c9749b36 SG |
248 | --- a/file1 |
249 | +++ b/file1 | |
250 | @@ -1 +1 @@ | |
251 | -A | |
252 | +G | |
253 | EOF | |
4dd1b5f9 | 254 | cat >expect2 <<-EOF && |
c9749b36 SG |
255 | <<<<<<< HEAD |
256 | D | |
257 | ======= | |
258 | G | |
4dd1b5f9 | 259 | >>>>>>> $commit... G |
c9749b36 | 260 | EOF |
1b1dce4b | 261 | git tag new-branch1 && |
ab736792 SB |
262 | test_must_fail git rebase -i master && |
263 | test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" && | |
28ed6e7b | 264 | test_cmp expect .git/rebase-merge/patch && |
82ebb0b6 | 265 | test_cmp expect2 file1 && |
0cb0e143 | 266 | test "$(git diff --name-status | |
ab736792 | 267 | sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 && |
28ed6e7b JS |
268 | test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) && |
269 | test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo) | |
1b1dce4b JS |
270 | ' |
271 | ||
66335298 NTND |
272 | test_expect_success 'show conflicted patch' ' |
273 | GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr && | |
fbd7a232 NTND |
274 | grep "show.*REBASE_HEAD" stderr && |
275 | # the original stopped-sha1 is abbreviated | |
276 | stopped_sha1="$(git rev-parse $(cat ".git/rebase-merge/stopped-sha"))" && | |
277 | test "$(git rev-parse REBASE_HEAD)" = "$stopped_sha1" | |
66335298 NTND |
278 | ' |
279 | ||
1b1dce4b JS |
280 | test_expect_success 'abort' ' |
281 | git rebase --abort && | |
780308d0 | 282 | test_cmp_rev new-branch1 HEAD && |
ab736792 | 283 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" && |
2caf20c5 | 284 | test_path_is_missing .git/rebase-merge |
1b1dce4b JS |
285 | ' |
286 | ||
b096374f IWC |
287 | test_expect_success 'abort with error when new base cannot be checked out' ' |
288 | git rm --cached file1 && | |
289 | git commit -m "remove file in base" && | |
290 | test_must_fail git rebase -i master > output 2>&1 && | |
e5c1272c | 291 | test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \ |
b096374f | 292 | output && |
e5c1272c | 293 | test_i18ngrep "file1" output && |
2caf20c5 | 294 | test_path_is_missing .git/rebase-merge && |
b096374f IWC |
295 | git reset --hard HEAD^ |
296 | ' | |
297 | ||
1b1dce4b JS |
298 | test_expect_success 'retain authorship' ' |
299 | echo A > file7 && | |
300 | git add file7 && | |
c54b7817 | 301 | test_tick && |
1b1dce4b JS |
302 | GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && |
303 | git tag twerp && | |
304 | git rebase -i --onto master HEAD^ && | |
305 | git show HEAD | grep "^Author: Twerp Snog" | |
306 | ' | |
307 | ||
a2a20b0d | 308 | test_expect_success 'retain authorship w/ conflicts' ' |
650161a2 JH |
309 | oGIT_AUTHOR_NAME=$GIT_AUTHOR_NAME && |
310 | test_when_finished "GIT_AUTHOR_NAME=\$oGIT_AUTHOR_NAME" && | |
311 | ||
a2a20b0d JS |
312 | git reset --hard twerp && |
313 | test_commit a conflict a conflict-a && | |
314 | git reset --hard twerp && | |
650161a2 JH |
315 | |
316 | GIT_AUTHOR_NAME=AttributeMe && | |
317 | export GIT_AUTHOR_NAME && | |
a2a20b0d | 318 | test_commit b conflict b conflict-b && |
650161a2 JH |
319 | GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME && |
320 | ||
a2a20b0d JS |
321 | test_must_fail git rebase -i conflict-a && |
322 | echo resolved >conflict && | |
323 | git add conflict && | |
324 | git rebase --continue && | |
780308d0 | 325 | test_cmp_rev conflict-a^0 HEAD^ && |
a2a20b0d JS |
326 | git show >out && |
327 | grep AttributeMe out | |
328 | ' | |
329 | ||
1b1dce4b JS |
330 | test_expect_success 'squash' ' |
331 | git reset --hard twerp && | |
332 | echo B > file7 && | |
c54b7817 | 333 | test_tick && |
1b1dce4b JS |
334 | GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 && |
335 | echo "******************************" && | |
b2dbacbd PW |
336 | ( |
337 | set_fake_editor && | |
338 | FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \ | |
339 | git rebase -i --onto master HEAD~2 | |
340 | ) && | |
1b1dce4b | 341 | test B = $(cat file7) && |
780308d0 | 342 | test_cmp_rev HEAD^ master |
1b1dce4b JS |
343 | ' |
344 | ||
345 | test_expect_success 'retain authorship when squashing' ' | |
81ab1cb4 | 346 | git show HEAD | grep "^Author: Twerp Snog" |
1b1dce4b JS |
347 | ' |
348 | ||
11aad464 | 349 | test_expect_success REBASE_P '-p handles "no changes" gracefully' ' |
34454e85 JS |
350 | HEAD=$(git rev-parse HEAD) && |
351 | git rebase -i -p HEAD^ && | |
71d9451e TR |
352 | git update-index --refresh && |
353 | git diff-files --quiet && | |
354 | git diff-index --quiet --cached HEAD -- && | |
34454e85 JS |
355 | test $HEAD = $(git rev-parse HEAD) |
356 | ' | |
357 | ||
11aad464 | 358 | test_expect_failure REBASE_P 'exchange two commits with -p' ' |
27ccd8d1 | 359 | git checkout H && |
b2dbacbd PW |
360 | ( |
361 | set_fake_editor && | |
362 | FAKE_LINES="2 1" git rebase -i -p HEAD~2 | |
363 | ) && | |
cddb42d2 JN |
364 | test H = $(git cat-file commit HEAD^ | sed -ne \$p) && |
365 | test G = $(git cat-file commit HEAD | sed -ne \$p) | |
366 | ' | |
367 | ||
11aad464 | 368 | test_expect_success REBASE_P 'preserve merges with -p' ' |
f09c9b8c JS |
369 | git checkout -b to-be-preserved master^ && |
370 | : > unrelated-file && | |
371 | git add unrelated-file && | |
372 | test_tick && | |
373 | git commit -m "unrelated" && | |
5352a82b | 374 | git checkout -b another-branch master && |
f09c9b8c JS |
375 | echo B > file1 && |
376 | test_tick && | |
377 | git commit -m J file1 && | |
378 | test_tick && | |
379 | git merge to-be-preserved && | |
380 | echo C > file1 && | |
381 | test_tick && | |
382 | git commit -m K file1 && | |
5352a82b SB |
383 | echo D > file1 && |
384 | test_tick && | |
385 | git commit -m L1 file1 && | |
386 | git checkout HEAD^ && | |
387 | echo 1 > unrelated-file && | |
388 | test_tick && | |
389 | git commit -m L2 unrelated-file && | |
390 | test_tick && | |
391 | git merge another-branch && | |
392 | echo E > file1 && | |
393 | test_tick && | |
394 | git commit -m M file1 && | |
395 | git checkout -b to-be-rebased && | |
18640d99 | 396 | test_tick && |
f09c9b8c | 397 | git rebase -i -p --onto branch1 master && |
71d9451e TR |
398 | git update-index --refresh && |
399 | git diff-files --quiet && | |
400 | git diff-index --quiet --cached HEAD -- && | |
780308d0 PW |
401 | test_cmp_rev HEAD~6 branch1 && |
402 | test_cmp_rev HEAD~4^2 to-be-preserved && | |
403 | test_cmp_rev HEAD^^2^ HEAD^^^ && | |
5352a82b SB |
404 | test $(git show HEAD~5:file1) = B && |
405 | test $(git show HEAD~3:file1) = C && | |
406 | test $(git show HEAD:file1) = E && | |
407 | test $(git show HEAD:unrelated-file) = 1 | |
f09c9b8c JS |
408 | ' |
409 | ||
11aad464 | 410 | test_expect_success REBASE_P 'edit ancestor with -p' ' |
b2dbacbd PW |
411 | ( |
412 | set_fake_editor && | |
413 | FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 | |
414 | ) && | |
a96dc01e TR |
415 | echo 2 > unrelated-file && |
416 | test_tick && | |
417 | git commit -m L2-modified --amend unrelated-file && | |
418 | git rebase --continue && | |
419 | git update-index --refresh && | |
420 | git diff-files --quiet && | |
421 | git diff-index --quiet --cached HEAD -- && | |
422 | test $(git show HEAD:unrelated-file) = 2 | |
423 | ' | |
424 | ||
18640d99 | 425 | test_expect_success '--continue tries to commit' ' |
6c8fbae6 | 426 | git reset --hard D && |
18640d99 | 427 | test_tick && |
b2dbacbd PW |
428 | ( |
429 | set_fake_editor && | |
430 | test_must_fail git rebase -i --onto new-branch1 HEAD^ && | |
431 | echo resolved > file1 && | |
432 | git add file1 && | |
433 | FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue | |
434 | ) && | |
780308d0 | 435 | test_cmp_rev HEAD^ new-branch1 && |
18640d99 JS |
436 | git show HEAD | grep chouette |
437 | ' | |
438 | ||
8e4a91bd | 439 | test_expect_success 'verbose flag is heeded, even after --continue' ' |
53f2ffa8 | 440 | git reset --hard master@{1} && |
8e4a91bd | 441 | test_tick && |
ab736792 | 442 | test_must_fail git rebase -v -i --onto new-branch1 HEAD^ && |
8e4a91bd JS |
443 | echo resolved > file1 && |
444 | git add file1 && | |
445 | git rebase --continue > output && | |
dc801e71 | 446 | grep "^ file1 | 2 +-$" output |
8e4a91bd JS |
447 | ' |
448 | ||
0d75bfe6 | 449 | test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' ' |
6368f3f8 | 450 | base=$(git rev-parse HEAD~4) && |
b2dbacbd PW |
451 | ( |
452 | set_fake_editor && | |
453 | FAKE_COMMIT_AMEND="ONCE" \ | |
454 | FAKE_LINES="1 squash 2 squash 3 squash 4" \ | |
455 | EXPECT_HEADER_COUNT=4 \ | |
456 | git rebase -i $base | |
457 | ) && | |
6368f3f8 JS |
458 | test $base = $(git rev-parse HEAD^) && |
459 | test 1 = $(git show | grep ONCE | wc -l) | |
460 | ' | |
461 | ||
0d75bfe6 | 462 | test_expect_success C_LOCALE_OUTPUT 'multi-fixup does not fire up editor' ' |
0205e72f MH |
463 | git checkout -b multi-fixup E && |
464 | base=$(git rev-parse HEAD~4) && | |
b2dbacbd PW |
465 | ( |
466 | set_fake_editor && | |
467 | FAKE_COMMIT_AMEND="NEVER" \ | |
468 | FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ | |
469 | git rebase -i $base | |
470 | ) && | |
0205e72f | 471 | test $base = $(git rev-parse HEAD^) && |
a25eb139 | 472 | test 0 = $(git show | grep NEVER | wc -l) && |
6c8fbae6 | 473 | git checkout @{-1} && |
0205e72f MH |
474 | git branch -D multi-fixup |
475 | ' | |
476 | ||
6bdcd0d2 MH |
477 | test_expect_success 'commit message used after conflict' ' |
478 | git checkout -b conflict-fixup conflict-branch && | |
479 | base=$(git rev-parse HEAD~4) && | |
b2dbacbd PW |
480 | ( |
481 | set_fake_editor && | |
482 | test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" \ | |
483 | git rebase -i $base && | |
484 | echo three > conflict && | |
485 | git add conflict && | |
486 | FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \ | |
487 | git rebase --continue | |
488 | ) && | |
6bdcd0d2 MH |
489 | test $base = $(git rev-parse HEAD^) && |
490 | test 1 = $(git show | grep ONCE | wc -l) && | |
6c8fbae6 | 491 | git checkout @{-1} && |
6bdcd0d2 MH |
492 | git branch -D conflict-fixup |
493 | ' | |
494 | ||
495 | test_expect_success 'commit message retained after conflict' ' | |
496 | git checkout -b conflict-squash conflict-branch && | |
497 | base=$(git rev-parse HEAD~4) && | |
b2dbacbd PW |
498 | ( |
499 | set_fake_editor && | |
500 | test_must_fail env FAKE_LINES="1 fixup 3 squash 4" \ | |
501 | git rebase -i $base && | |
502 | echo three > conflict && | |
503 | git add conflict && | |
504 | FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \ | |
505 | git rebase --continue | |
506 | ) && | |
6bdcd0d2 MH |
507 | test $base = $(git rev-parse HEAD^) && |
508 | test 2 = $(git show | grep TWICE | wc -l) && | |
6c8fbae6 | 509 | git checkout @{-1} && |
6bdcd0d2 MH |
510 | git branch -D conflict-squash |
511 | ' | |
512 | ||
c9749b36 SG |
513 | test_expect_success C_LOCALE_OUTPUT 'squash and fixup generate correct log messages' ' |
514 | cat >expect-squash-fixup <<-\EOF && | |
515 | B | |
0205e72f | 516 | |
c9749b36 | 517 | D |
0205e72f | 518 | |
c9749b36 SG |
519 | ONCE |
520 | EOF | |
0205e72f MH |
521 | git checkout -b squash-fixup E && |
522 | base=$(git rev-parse HEAD~4) && | |
b2dbacbd PW |
523 | ( |
524 | set_fake_editor && | |
525 | FAKE_COMMIT_AMEND="ONCE" \ | |
526 | FAKE_LINES="1 fixup 2 squash 3 fixup 4" \ | |
527 | EXPECT_HEADER_COUNT=4 \ | |
528 | git rebase -i $base | |
529 | ) && | |
0205e72f MH |
530 | git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup && |
531 | test_cmp expect-squash-fixup actual-squash-fixup && | |
60b61588 PW |
532 | git cat-file commit HEAD@{2} | |
533 | grep "^# This is a combination of 3 commits\." && | |
534 | git cat-file commit HEAD@{3} | | |
535 | grep "^# This is a combination of 2 commits\." && | |
6c8fbae6 | 536 | git checkout @{-1} && |
0205e72f MH |
537 | git branch -D squash-fixup |
538 | ' | |
539 | ||
0d75bfe6 | 540 | test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' ' |
234b3dae MH |
541 | git checkout -b skip-comments E && |
542 | base=$(git rev-parse HEAD~4) && | |
b2dbacbd PW |
543 | ( |
544 | set_fake_editor && | |
545 | FAKE_COMMIT_AMEND="ONCE" \ | |
546 | FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \ | |
547 | EXPECT_HEADER_COUNT=4 \ | |
548 | git rebase -i $base | |
549 | ) && | |
234b3dae MH |
550 | test $base = $(git rev-parse HEAD^) && |
551 | test 1 = $(git show | grep ONCE | wc -l) && | |
6c8fbae6 | 552 | git checkout @{-1} && |
234b3dae MH |
553 | git branch -D skip-comments |
554 | ' | |
555 | ||
0d75bfe6 | 556 | test_expect_success C_LOCALE_OUTPUT 'squash ignores blank lines' ' |
234b3dae MH |
557 | git checkout -b skip-blank-lines E && |
558 | base=$(git rev-parse HEAD~4) && | |
b2dbacbd PW |
559 | ( |
560 | set_fake_editor && | |
561 | FAKE_COMMIT_AMEND="ONCE" \ | |
562 | FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \ | |
563 | EXPECT_HEADER_COUNT=4 \ | |
564 | git rebase -i $base | |
565 | ) && | |
234b3dae MH |
566 | test $base = $(git rev-parse HEAD^) && |
567 | test 1 = $(git show | grep ONCE | wc -l) && | |
6c8fbae6 | 568 | git checkout @{-1} && |
234b3dae MH |
569 | git branch -D skip-blank-lines |
570 | ' | |
571 | ||
fb47cfbd | 572 | test_expect_success 'squash works as expected' ' |
6c4c44c4 | 573 | git checkout -b squash-works no-conflict-branch && |
fb47cfbd | 574 | one=$(git rev-parse HEAD~3) && |
b2dbacbd PW |
575 | ( |
576 | set_fake_editor && | |
577 | FAKE_LINES="1 s 3 2" EXPECT_HEADER_COUNT=2 git rebase -i HEAD~3 | |
578 | ) && | |
fb47cfbd JS |
579 | test $one = $(git rev-parse HEAD~2) |
580 | ' | |
581 | ||
582 | test_expect_success 'interrupted squash works as expected' ' | |
6c4c44c4 | 583 | git checkout -b interrupted-squash conflict-branch && |
fb47cfbd | 584 | one=$(git rev-parse HEAD~3) && |
b2dbacbd PW |
585 | ( |
586 | set_fake_editor && | |
587 | test_must_fail env FAKE_LINES="1 squash 3 2" \ | |
588 | git rebase -i HEAD~3 | |
589 | ) && | |
0590ff26 | 590 | test_write_lines one two four > conflict && |
fb47cfbd | 591 | git add conflict && |
ab736792 | 592 | test_must_fail git rebase --continue && |
fb47cfbd JS |
593 | echo resolved > conflict && |
594 | git add conflict && | |
595 | git rebase --continue && | |
596 | test $one = $(git rev-parse HEAD~2) | |
597 | ' | |
598 | ||
1d25c8cf | 599 | test_expect_success 'interrupted squash works as expected (case 2)' ' |
6c4c44c4 | 600 | git checkout -b interrupted-squash2 conflict-branch && |
1d25c8cf | 601 | one=$(git rev-parse HEAD~3) && |
b2dbacbd PW |
602 | ( |
603 | set_fake_editor && | |
604 | test_must_fail env FAKE_LINES="3 squash 1 2" \ | |
605 | git rebase -i HEAD~3 | |
606 | ) && | |
0590ff26 | 607 | test_write_lines one four > conflict && |
1d25c8cf | 608 | git add conflict && |
ab736792 | 609 | test_must_fail git rebase --continue && |
0590ff26 | 610 | test_write_lines one two four > conflict && |
1d25c8cf | 611 | git add conflict && |
ab736792 | 612 | test_must_fail git rebase --continue && |
1d25c8cf JS |
613 | echo resolved > conflict && |
614 | git add conflict && | |
615 | git rebase --continue && | |
616 | test $one = $(git rev-parse HEAD~2) | |
617 | ' | |
618 | ||
3f213981 | 619 | test_expect_success '--continue tries to commit, even for "edit"' ' |
96ffe892 JS |
620 | echo unrelated > file7 && |
621 | git add file7 && | |
622 | test_tick && | |
623 | git commit -m "unrelated change" && | |
be6ff208 JS |
624 | parent=$(git rev-parse HEAD^) && |
625 | test_tick && | |
b2dbacbd PW |
626 | ( |
627 | set_fake_editor && | |
628 | FAKE_LINES="edit 1" git rebase -i HEAD^ && | |
629 | echo edited > file7 && | |
630 | git add file7 && | |
631 | FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue | |
632 | ) && | |
be6ff208 JS |
633 | test edited = $(git show HEAD:file7) && |
634 | git show HEAD | grep chouette && | |
635 | test $parent = $(git rev-parse HEAD^) | |
636 | ' | |
637 | ||
dc7f55cb SB |
638 | test_expect_success 'aborted --continue does not squash commits after "edit"' ' |
639 | old=$(git rev-parse HEAD) && | |
640 | test_tick && | |
b2dbacbd PW |
641 | ( |
642 | set_fake_editor && | |
643 | FAKE_LINES="edit 1" git rebase -i HEAD^ && | |
644 | echo "edited again" > file7 && | |
645 | git add file7 && | |
646 | test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue | |
647 | ) && | |
a3ec9eaf EN |
648 | test $old = $(git rev-parse HEAD) && |
649 | git rebase --abort | |
dc7f55cb SB |
650 | ' |
651 | ||
f8aa1b69 SB |
652 | test_expect_success 'auto-amend only edited commits after "edit"' ' |
653 | test_tick && | |
b2dbacbd PW |
654 | ( |
655 | set_fake_editor && | |
656 | FAKE_LINES="edit 1" git rebase -i HEAD^ && | |
657 | echo "edited again" > file7 && | |
658 | git add file7 && | |
659 | FAKE_COMMIT_MESSAGE="edited file7 again" git commit && | |
660 | echo "and again" > file7 && | |
661 | git add file7 && | |
662 | test_tick && | |
663 | test_must_fail env FAKE_COMMIT_MESSAGE="and again" \ | |
664 | git rebase --continue | |
665 | ) && | |
f8aa1b69 SB |
666 | git rebase --abort |
667 | ' | |
668 | ||
ffaaed88 MM |
669 | test_expect_success 'clean error after failed "exec"' ' |
670 | test_tick && | |
671 | test_when_finished "git rebase --abort || :" && | |
b2dbacbd PW |
672 | ( |
673 | set_fake_editor && | |
674 | test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ | |
675 | ) && | |
ffaaed88 MM |
676 | echo "edited again" > file7 && |
677 | git add file7 && | |
678 | test_must_fail git rebase --continue 2>error && | |
18633e1a | 679 | test_i18ngrep "you have staged changes in your working tree" error |
ffaaed88 MM |
680 | ' |
681 | ||
73697a0b JS |
682 | test_expect_success 'rebase a detached HEAD' ' |
683 | grandparent=$(git rev-parse HEAD~2) && | |
684 | git checkout $(git rev-parse HEAD) && | |
685 | test_tick && | |
b2dbacbd PW |
686 | ( |
687 | set_fake_editor && | |
688 | FAKE_LINES="2 1" git rebase -i HEAD~2 | |
689 | ) && | |
73697a0b JS |
690 | test $grandparent = $(git rev-parse HEAD~2) |
691 | ' | |
692 | ||
752527f5 JS |
693 | test_expect_success 'rebase a commit violating pre-commit' ' |
694 | ||
695 | mkdir -p .git/hooks && | |
7bec7f50 JH |
696 | write_script .git/hooks/pre-commit <<-\EOF && |
697 | test -z "$(git diff --cached --check)" | |
698 | EOF | |
752527f5 JS |
699 | echo "monde! " >> file1 && |
700 | test_tick && | |
ab736792 | 701 | test_must_fail git commit -m doesnt-verify file1 && |
752527f5 JS |
702 | git commit -m doesnt-verify --no-verify file1 && |
703 | test_tick && | |
b2dbacbd PW |
704 | ( |
705 | set_fake_editor && | |
706 | FAKE_LINES=2 git rebase -i HEAD~2 | |
707 | ) | |
752527f5 JS |
708 | ' |
709 | ||
077b725f JH |
710 | test_expect_success 'rebase with a file named HEAD in worktree' ' |
711 | ||
712 | rm -fr .git/hooks && | |
713 | git reset --hard && | |
714 | git checkout -b branch3 A && | |
715 | ||
716 | ( | |
717 | GIT_AUTHOR_NAME="Squashed Away" && | |
718 | export GIT_AUTHOR_NAME && | |
719 | >HEAD && | |
720 | git add HEAD && | |
721 | git commit -m "Add head" && | |
722 | >BODY && | |
723 | git add BODY && | |
724 | git commit -m "Add body" | |
725 | ) && | |
726 | ||
b2dbacbd PW |
727 | ( |
728 | set_fake_editor && | |
729 | FAKE_LINES="1 squash 2" git rebase -i @{-1} | |
730 | ) && | |
077b725f JH |
731 | test "$(git show -s --pretty=format:%an)" = "Squashed Away" |
732 | ||
733 | ' | |
734 | ||
ff74126c JS |
735 | test_expect_success 'do "noop" when there is nothing to cherry-pick' ' |
736 | ||
737 | git checkout -b branch4 HEAD && | |
738 | GIT_EDITOR=: git commit --amend \ | |
2dec68cf | 739 | --author="Somebody else <somebody@else.com>" && |
ff74126c JS |
740 | test $(git rev-parse branch3) != $(git rev-parse branch4) && |
741 | git rebase -i branch3 && | |
780308d0 | 742 | test_cmp_rev branch3 branch4 |
ff74126c JS |
743 | |
744 | ' | |
745 | ||
96747696 JH |
746 | test_expect_success 'submodule rebase setup' ' |
747 | git checkout A && | |
748 | mkdir sub && | |
749 | ( | |
750 | cd sub && git init && >elif && | |
751 | git add elif && git commit -m "submodule initial" | |
752 | ) && | |
753 | echo 1 >file1 && | |
2dec68cf | 754 | git add file1 sub && |
96747696 JH |
755 | test_tick && |
756 | git commit -m "One" && | |
757 | echo 2 >file1 && | |
758 | test_tick && | |
759 | git commit -a -m "Two" && | |
760 | ( | |
761 | cd sub && echo 3 >elif && | |
762 | git commit -a -m "submodule second" | |
763 | ) && | |
764 | test_tick && | |
765 | git commit -a -m "Three changes submodule" | |
766 | ' | |
767 | ||
94c88ede | 768 | test_expect_success 'submodule rebase -i' ' |
b2dbacbd PW |
769 | ( |
770 | set_fake_editor && | |
771 | FAKE_LINES="1 squash 2 3" git rebase -i A | |
772 | ) | |
96747696 JH |
773 | ' |
774 | ||
a6754cda JK |
775 | test_expect_success 'submodule conflict setup' ' |
776 | git tag submodule-base && | |
777 | git checkout HEAD^ && | |
778 | ( | |
779 | cd sub && git checkout HEAD^ && echo 4 >elif && | |
780 | git add elif && git commit -m "submodule conflict" | |
781 | ) && | |
782 | git add sub && | |
783 | test_tick && | |
784 | git commit -m "Conflict in submodule" && | |
785 | git tag submodule-topic | |
786 | ' | |
787 | ||
788 | test_expect_success 'rebase -i continue with only submodule staged' ' | |
789 | test_must_fail git rebase -i submodule-base && | |
790 | git add sub && | |
791 | git rebase --continue && | |
792 | test $(git rev-parse submodule-base) != $(git rev-parse HEAD) | |
793 | ' | |
794 | ||
795 | test_expect_success 'rebase -i continue with unstaged submodule' ' | |
796 | git checkout submodule-topic && | |
797 | git reset --hard && | |
798 | test_must_fail git rebase -i submodule-base && | |
799 | git reset && | |
800 | git rebase --continue && | |
780308d0 | 801 | test_cmp_rev submodule-base HEAD |
a6754cda JK |
802 | ' |
803 | ||
0e757e30 JS |
804 | test_expect_success 'avoid unnecessary reset' ' |
805 | git checkout master && | |
a6754cda | 806 | git reset --hard && |
0e496492 | 807 | test-tool chmtime =123456789 file3 && |
0e757e30 JS |
808 | git update-index --refresh && |
809 | HEAD=$(git rev-parse HEAD) && | |
810 | git rebase -i HEAD~4 && | |
811 | test $HEAD = $(git rev-parse HEAD) && | |
deb9845a | 812 | MTIME=$(test-tool chmtime --get file3) && |
0e757e30 JS |
813 | test 123456789 = $MTIME |
814 | ' | |
815 | ||
6741aa6c BG |
816 | test_expect_success 'reword' ' |
817 | git checkout -b reword-branch master && | |
b2dbacbd PW |
818 | ( |
819 | set_fake_editor && | |
820 | FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \ | |
821 | git rebase -i A && | |
822 | git show HEAD | grep "E changed" && | |
823 | test $(git rev-parse master) != $(git rev-parse HEAD) && | |
780308d0 | 824 | test_cmp_rev master^ HEAD^ && |
b2dbacbd PW |
825 | FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \ |
826 | git rebase -i A && | |
827 | git show HEAD^ | grep "D changed" && | |
828 | FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" \ | |
829 | git rebase -i A && | |
830 | git show HEAD~3 | grep "B changed" && | |
831 | FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" \ | |
832 | git rebase -i A | |
833 | ) && | |
6741aa6c BG |
834 | git show HEAD~2 | grep "C changed" |
835 | ' | |
836 | ||
eb2151bb TR |
837 | test_expect_success 'rebase -i can copy notes' ' |
838 | git config notes.rewrite.rebase true && | |
839 | git config notes.rewriteRef "refs/notes/*" && | |
840 | test_commit n1 && | |
841 | test_commit n2 && | |
842 | test_commit n3 && | |
843 | git notes add -m"a note" n3 && | |
6f87f038 | 844 | git rebase -i --onto n1 n2 && |
eb2151bb TR |
845 | test "a note" = "$(git notes show HEAD)" |
846 | ' | |
847 | ||
eb2151bb | 848 | test_expect_success 'rebase -i can copy notes over a fixup' ' |
c9749b36 SG |
849 | cat >expect <<-\EOF && |
850 | an earlier note | |
851 | ||
852 | a note | |
853 | EOF | |
eb2151bb TR |
854 | git reset --hard n3 && |
855 | git notes add -m"an earlier note" n2 && | |
b2dbacbd PW |
856 | ( |
857 | set_fake_editor && | |
858 | GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 f 2" \ | |
859 | git rebase -i n1 | |
860 | ) && | |
eb2151bb TR |
861 | git notes show > output && |
862 | test_cmp expect output | |
863 | ' | |
864 | ||
2ec33cdd DO |
865 | test_expect_success 'rebase while detaching HEAD' ' |
866 | git symbolic-ref HEAD && | |
867 | grandparent=$(git rev-parse HEAD~2) && | |
868 | test_tick && | |
b2dbacbd PW |
869 | ( |
870 | set_fake_editor && | |
871 | FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 | |
872 | ) && | |
2ec33cdd DO |
873 | test $grandparent = $(git rev-parse HEAD~2) && |
874 | test_must_fail git symbolic-ref HEAD | |
875 | ' | |
876 | ||
b4995494 MB |
877 | test_tick # Ensure that the rebased commits get a different timestamp. |
878 | test_expect_success 'always cherry-pick with --no-ff' ' | |
879 | git checkout no-ff-branch && | |
880 | git tag original-no-ff-branch && | |
881 | git rebase -i --no-ff A && | |
b4995494 MB |
882 | for p in 0 1 2 |
883 | do | |
884 | test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) && | |
885 | git diff HEAD~$p original-no-ff-branch~$p > out && | |
1c5e94f4 | 886 | test_must_be_empty out |
b4995494 | 887 | done && |
780308d0 | 888 | test_cmp_rev HEAD~3 original-no-ff-branch~3 && |
b4995494 | 889 | git diff HEAD~3 original-no-ff-branch~3 > out && |
1c5e94f4 | 890 | test_must_be_empty out |
b4995494 MB |
891 | ' |
892 | ||
57f2b6b2 JH |
893 | test_expect_success 'set up commits with funny messages' ' |
894 | git checkout -b funny A && | |
895 | echo >>file1 && | |
896 | test_tick && | |
897 | git commit -a -m "end with slash\\" && | |
898 | echo >>file1 && | |
899 | test_tick && | |
938791cd BC |
900 | git commit -a -m "something (\000) that looks like octal" && |
901 | echo >>file1 && | |
902 | test_tick && | |
903 | git commit -a -m "something (\n) that looks like a newline" && | |
904 | echo >>file1 && | |
905 | test_tick && | |
57f2b6b2 JH |
906 | git commit -a -m "another commit" |
907 | ' | |
908 | ||
909 | test_expect_success 'rebase-i history with funny messages' ' | |
910 | git rev-list A..funny >expect && | |
911 | test_tick && | |
b2dbacbd PW |
912 | ( |
913 | set_fake_editor && | |
914 | FAKE_LINES="1 2 3 4" git rebase -i A | |
915 | ) && | |
57f2b6b2 JH |
916 | git rev-list A.. >actual && |
917 | test_cmp expect actual | |
918 | ' | |
919 | ||
c2145384 LK |
920 | test_expect_success 'prepare for rebase -i --exec' ' |
921 | git checkout master && | |
922 | git checkout -b execute && | |
923 | test_commit one_exec main.txt one_exec && | |
924 | test_commit two_exec main.txt two_exec && | |
925 | test_commit three_exec main.txt three_exec | |
926 | ' | |
927 | ||
c2145384 | 928 | test_expect_success 'running "git rebase -i --exec git show HEAD"' ' |
c2145384 | 929 | ( |
b2dbacbd PW |
930 | set_fake_editor && |
931 | git rebase -i --exec "git show HEAD" HEAD~2 >actual && | |
c2145384 LK |
932 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && |
933 | export FAKE_LINES && | |
934 | git rebase -i HEAD~2 >expect | |
935 | ) && | |
936 | sed -e "1,9d" expect >expected && | |
937 | test_cmp expected actual | |
938 | ' | |
939 | ||
c2145384 LK |
940 | test_expect_success 'running "git rebase --exec git show HEAD -i"' ' |
941 | git reset --hard execute && | |
c2145384 | 942 | ( |
b2dbacbd PW |
943 | set_fake_editor && |
944 | git rebase --exec "git show HEAD" -i HEAD~2 >actual && | |
c2145384 LK |
945 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && |
946 | export FAKE_LINES && | |
947 | git rebase -i HEAD~2 >expect | |
948 | ) && | |
949 | sed -e "1,9d" expect >expected && | |
950 | test_cmp expected actual | |
951 | ' | |
952 | ||
c2145384 LK |
953 | test_expect_success 'running "git rebase -ix git show HEAD"' ' |
954 | git reset --hard execute && | |
c2145384 | 955 | ( |
b2dbacbd PW |
956 | set_fake_editor && |
957 | git rebase -ix "git show HEAD" HEAD~2 >actual && | |
c2145384 LK |
958 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && |
959 | export FAKE_LINES && | |
960 | git rebase -i HEAD~2 >expect | |
961 | ) && | |
962 | sed -e "1,9d" expect >expected && | |
963 | test_cmp expected actual | |
964 | ' | |
965 | ||
966 | ||
967 | test_expect_success 'rebase -ix with several <CMD>' ' | |
968 | git reset --hard execute && | |
c2145384 | 969 | ( |
b2dbacbd PW |
970 | set_fake_editor && |
971 | git rebase -ix "git show HEAD; pwd" HEAD~2 >actual && | |
c2145384 LK |
972 | FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" && |
973 | export FAKE_LINES && | |
974 | git rebase -i HEAD~2 >expect | |
975 | ) && | |
976 | sed -e "1,9d" expect >expected && | |
977 | test_cmp expected actual | |
978 | ' | |
979 | ||
c2145384 LK |
980 | test_expect_success 'rebase -ix with several instances of --exec' ' |
981 | git reset --hard execute && | |
c2145384 | 982 | ( |
b2dbacbd PW |
983 | set_fake_editor && |
984 | git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual && | |
c2145384 LK |
985 | FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2 |
986 | exec_git_show_HEAD exec_pwd" && | |
987 | export FAKE_LINES && | |
988 | git rebase -i HEAD~2 >expect | |
989 | ) && | |
990 | sed -e "1,11d" expect >expected && | |
991 | test_cmp expected actual | |
992 | ' | |
993 | ||
0d75bfe6 | 994 | test_expect_success C_LOCALE_OUTPUT 'rebase -ix with --autosquash' ' |
c2145384 LK |
995 | git reset --hard execute && |
996 | git checkout -b autosquash && | |
997 | echo second >second.txt && | |
998 | git add second.txt && | |
999 | git commit -m "fixup! two_exec" && | |
1000 | echo bis >bis.txt && | |
1001 | git add bis.txt && | |
1002 | git commit -m "fixup! two_exec" && | |
88a92b6c PW |
1003 | git checkout -b autosquash_actual && |
1004 | git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual && | |
c2145384 LK |
1005 | git checkout autosquash && |
1006 | ( | |
b2dbacbd | 1007 | set_fake_editor && |
c2145384 LK |
1008 | git checkout -b autosquash_expected && |
1009 | FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" && | |
1010 | export FAKE_LINES && | |
1011 | git rebase -i HEAD~4 >expect | |
1012 | ) && | |
1013 | sed -e "1,13d" expect >expected && | |
1014 | test_cmp expected actual | |
1015 | ' | |
1016 | ||
78ec2400 | 1017 | test_expect_success 'rebase --exec works without -i ' ' |
c2145384 | 1018 | git reset --hard execute && |
78ec2400 SB |
1019 | rm -rf exec_output && |
1020 | EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual && | |
1021 | test_i18ngrep "Successfully rebased and updated" actual && | |
1022 | test_line_count = 2 exec_output && | |
1023 | test_path_is_missing invoked_editor | |
c2145384 LK |
1024 | ' |
1025 | ||
c2145384 LK |
1026 | test_expect_success 'rebase -i --exec without <CMD>' ' |
1027 | git reset --hard execute && | |
3bb0923f PSU |
1028 | test_must_fail git rebase -i --exec 2>actual && |
1029 | test_i18ngrep "requires a value" actual && | |
c2145384 LK |
1030 | git checkout master |
1031 | ' | |
1032 | ||
b64b7feb CW |
1033 | test_expect_success 'rebase -i --root re-order and drop commits' ' |
1034 | git checkout E && | |
b2dbacbd PW |
1035 | ( |
1036 | set_fake_editor && | |
1037 | FAKE_LINES="3 1 2 5" git rebase -i --root | |
1038 | ) && | |
b64b7feb CW |
1039 | test E = $(git cat-file commit HEAD | sed -ne \$p) && |
1040 | test B = $(git cat-file commit HEAD^ | sed -ne \$p) && | |
1041 | test A = $(git cat-file commit HEAD^^ | sed -ne \$p) && | |
1042 | test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) && | |
1043 | test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ ) | |
1044 | ' | |
1045 | ||
1046 | test_expect_success 'rebase -i --root retain root commit author and message' ' | |
1047 | git checkout A && | |
1048 | echo B >file7 && | |
1049 | git add file7 && | |
1050 | GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && | |
b2dbacbd PW |
1051 | ( |
1052 | set_fake_editor && | |
1053 | FAKE_LINES="2" git rebase -i --root | |
1054 | ) && | |
b64b7feb CW |
1055 | git cat-file commit HEAD | grep -q "^author Twerp Snog" && |
1056 | git cat-file commit HEAD | grep -q "^different author$" | |
1057 | ' | |
1058 | ||
1059 | test_expect_success 'rebase -i --root temporary sentinel commit' ' | |
1060 | git checkout B && | |
b2dbacbd PW |
1061 | ( |
1062 | set_fake_editor && | |
1063 | test_must_fail env FAKE_LINES="2" git rebase -i --root | |
1064 | ) && | |
4dd1b5f9 | 1065 | git cat-file commit HEAD | grep "^tree $EMPTY_TREE" && |
b64b7feb CW |
1066 | git rebase --abort |
1067 | ' | |
1068 | ||
2147f844 CW |
1069 | test_expect_success 'rebase -i --root fixup root commit' ' |
1070 | git checkout B && | |
b2dbacbd PW |
1071 | ( |
1072 | set_fake_editor && | |
1073 | FAKE_LINES="1 fixup 2" git rebase -i --root | |
1074 | ) && | |
2147f844 CW |
1075 | test A = $(git cat-file commit HEAD | sed -ne \$p) && |
1076 | test B = $(git show HEAD:file1) && | |
1077 | test 0 = $(git cat-file commit HEAD | grep -c ^parent\ ) | |
1078 | ' | |
1079 | ||
450efe2d | 1080 | test_expect_success 'rebase -i --root reword original root commit' ' |
3a36ca08 | 1081 | test_when_finished "test_might_fail git rebase --abort" && |
450efe2d | 1082 | git checkout -b reword-original-root-branch master && |
b2dbacbd PW |
1083 | ( |
1084 | set_fake_editor && | |
1085 | FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \ | |
1086 | git rebase -i --root | |
1087 | ) && | |
87881055 TZ |
1088 | git show HEAD^ | grep "A changed" && |
1089 | test -z "$(git show -s --format=%p HEAD^)" | |
3a36ca08 TZ |
1090 | ' |
1091 | ||
450efe2d PW |
1092 | test_expect_success 'rebase -i --root reword new root commit' ' |
1093 | test_when_finished "test_might_fail git rebase --abort" && | |
1094 | git checkout -b reword-now-root-branch master && | |
b2dbacbd PW |
1095 | ( |
1096 | set_fake_editor && | |
1097 | FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \ | |
1098 | git rebase -i --root | |
1099 | ) && | |
450efe2d PW |
1100 | git show HEAD^ | grep "C changed" && |
1101 | test -z "$(git show -s --format=%p HEAD^)" | |
1102 | ' | |
1103 | ||
cc8d872e | 1104 | test_expect_success 'rebase -i --root when root has untracked file conflict' ' |
a9279c67 PW |
1105 | test_when_finished "reset_rebase" && |
1106 | git checkout -b failing-root-pick A && | |
1107 | echo x >file2 && | |
1108 | git rm file1 && | |
1109 | git commit -m "remove file 1 add file 2" && | |
1110 | echo z >file1 && | |
b2dbacbd PW |
1111 | ( |
1112 | set_fake_editor && | |
1113 | test_must_fail env FAKE_LINES="1 2" git rebase -i --root | |
1114 | ) && | |
a9279c67 PW |
1115 | rm file1 && |
1116 | git rebase --continue && | |
1117 | test "$(git log -1 --format=%B)" = "remove file 1 add file 2" && | |
1118 | test "$(git rev-list --count HEAD)" = 2 | |
1119 | ' | |
1120 | ||
1121 | test_expect_success 'rebase -i --root reword root when root has untracked file conflict' ' | |
1122 | test_when_finished "reset_rebase" && | |
1123 | echo z>file1 && | |
b2dbacbd PW |
1124 | ( |
1125 | set_fake_editor && | |
1126 | test_must_fail env FAKE_LINES="reword 1 2" \ | |
1127 | FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root && | |
1128 | rm file1 && | |
1129 | FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue | |
1130 | ) && | |
a9279c67 PW |
1131 | test "$(git log -1 --format=%B HEAD^)" = "Reworded A" && |
1132 | test "$(git rev-list --count HEAD)" = 2 | |
1133 | ' | |
1134 | ||
0d75bfe6 | 1135 | test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' ' |
450efe2d | 1136 | git checkout reword-original-root-branch && |
9f4981ba AW |
1137 | git reset --hard && |
1138 | git checkout conflict-branch && | |
b2dbacbd PW |
1139 | ( |
1140 | set_fake_editor && | |
10cdb9f3 | 1141 | test_must_fail git rebase -f --apply --onto HEAD~2 HEAD~ && |
b2dbacbd PW |
1142 | test_must_fail git rebase --edit-todo |
1143 | ) && | |
9f4981ba AW |
1144 | git rebase --abort |
1145 | ' | |
1146 | ||
1147 | test_expect_success 'rebase --edit-todo can be used to modify todo' ' | |
1148 | git reset --hard && | |
1149 | git checkout no-conflict-branch^0 && | |
b2dbacbd PW |
1150 | ( |
1151 | set_fake_editor && | |
1152 | FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 && | |
1153 | FAKE_LINES="2 1" git rebase --edit-todo && | |
1154 | git rebase --continue | |
1155 | ) && | |
9f4981ba AW |
1156 | test M = $(git cat-file commit HEAD^ | sed -ne \$p) && |
1157 | test L = $(git cat-file commit HEAD | sed -ne \$p) | |
1158 | ' | |
1159 | ||
26cd160c RR |
1160 | test_expect_success 'rebase -i produces readable reflog' ' |
1161 | git reset --hard && | |
1162 | git branch -f branch-reflog-test H && | |
1163 | git rebase -i --onto I F branch-reflog-test && | |
1164 | cat >expect <<-\EOF && | |
c2417d3a EN |
1165 | rebase (finish): returning to refs/heads/branch-reflog-test |
1166 | rebase (pick): H | |
1167 | rebase (pick): G | |
1168 | rebase (start): checkout I | |
26cd160c | 1169 | EOF |
d0ab0584 DT |
1170 | git reflog -n4 HEAD | |
1171 | sed "s/[^:]*: //" >actual && | |
26cd160c RR |
1172 | test_cmp expect actual |
1173 | ' | |
1174 | ||
180bad3d JK |
1175 | test_expect_success 'rebase -i respects core.commentchar' ' |
1176 | git reset --hard && | |
1177 | git checkout E^0 && | |
aac6c2f4 | 1178 | test_config core.commentchar "\\" && |
180bad3d JK |
1179 | write_script remove-all-but-first.sh <<-\EOF && |
1180 | sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" && | |
1181 | mv "$1.tmp" "$1" | |
1182 | EOF | |
b2dbacbd PW |
1183 | ( |
1184 | test_set_editor "$(pwd)/remove-all-but-first.sh" && | |
1185 | git rebase -i B | |
1186 | ) && | |
180bad3d JK |
1187 | test B = $(git cat-file commit HEAD^ | sed -ne \$p) |
1188 | ' | |
1189 | ||
882cd237 | 1190 | test_expect_success 'rebase -i respects core.commentchar=auto' ' |
66458388 JS |
1191 | test_config core.commentchar auto && |
1192 | write_script copy-edit-script.sh <<-\EOF && | |
1193 | cp "$1" edit-script | |
1194 | EOF | |
66458388 | 1195 | test_when_finished "git rebase --abort || :" && |
b2dbacbd PW |
1196 | ( |
1197 | test_set_editor "$(pwd)/copy-edit-script.sh" && | |
1198 | git rebase -i HEAD^ | |
1199 | ) && | |
66458388 JS |
1200 | test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)" |
1201 | ' | |
1202 | ||
2e6e276d | 1203 | test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' ' |
6567dc05 RR |
1204 | test_when_finished "git branch -D torebase" && |
1205 | git checkout -b torebase branch1 && | |
1206 | upstream=$(git rev-parse ":/J") && | |
1207 | onto=$(git rev-parse ":/A") && | |
1208 | git rebase --onto $onto $upstream && | |
1209 | git reset --hard branch1 && | |
1210 | git rebase --onto ":/A" ":/J" && | |
1211 | git checkout branch1 | |
1212 | ' | |
1213 | ||
db2b3b82 AF |
1214 | test_expect_success 'rebase -i with --strategy and -X' ' |
1215 | git checkout -b conflict-merge-use-theirs conflict-branch && | |
1216 | git reset --hard HEAD^ && | |
1217 | echo five >conflict && | |
1218 | echo Z >file1 && | |
1219 | git commit -a -m "one file conflict" && | |
1220 | EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch && | |
1221 | test $(git show conflict-branch:conflict) = $(cat conflict) && | |
1222 | test $(cat file1) = Z | |
1223 | ' | |
1224 | ||
040fd39e FR |
1225 | test_expect_success 'interrupted rebase -i with --strategy and -X' ' |
1226 | git checkout -b conflict-merge-use-theirs-interrupted conflict-branch && | |
1227 | git reset --hard HEAD^ && | |
1228 | >breakpoint && | |
1229 | git add breakpoint && | |
1230 | git commit -m "breakpoint for interactive mode" && | |
1231 | echo five >conflict && | |
1232 | echo Z >file1 && | |
1233 | git commit -a -m "one file conflict" && | |
b2dbacbd PW |
1234 | ( |
1235 | set_fake_editor && | |
1236 | FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive \ | |
1237 | -Xours conflict-branch | |
1238 | ) && | |
040fd39e FR |
1239 | git rebase --continue && |
1240 | test $(git show conflict-branch:conflict) = $(cat conflict) && | |
1241 | test $(cat file1) = Z | |
1242 | ' | |
1243 | ||
89b0230a | 1244 | test_expect_success 'rebase -i error on commits with \ in message' ' |
99094a7a | 1245 | current_head=$(git rev-parse HEAD) && |
89b0230a MM |
1246 | test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" && |
1247 | test_commit TO-REMOVE will-conflict old-content && | |
1248 | test_commit "\temp" will-conflict new-content dummy && | |
512477b1 | 1249 | test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error && |
89b0230a MM |
1250 | test_expect_code 1 grep " emp" error |
1251 | ' | |
1252 | ||
4dd1b5f9 | 1253 | test_expect_success SHA1 'short SHA-1 setup' ' |
66ae9a57 ES |
1254 | test_when_finished "git checkout master" && |
1255 | git checkout --orphan collide && | |
1256 | git rm -rf . && | |
1257 | ( | |
1258 | unset test_tick && | |
1259 | test_commit collide1 collide && | |
1260 | test_commit --notick collide2 collide && | |
1261 | test_commit --notick collide3 collide | |
1262 | ) | |
1263 | ' | |
1264 | ||
4dd1b5f9 | 1265 | test_expect_success SHA1 'short SHA-1 collide' ' |
66ae9a57 ES |
1266 | test_when_finished "reset_rebase && git checkout master" && |
1267 | git checkout collide && | |
b6992261 JS |
1268 | colliding_sha1=6bcda37 && |
1269 | test $colliding_sha1 = "$(git rev-parse HEAD | cut -c 1-7)" && | |
66ae9a57 | 1270 | ( |
8cf8f9b4 JS |
1271 | unset test_tick && |
1272 | test_tick && | |
1273 | set_fake_editor && | |
1274 | FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \ | |
b6992261 JS |
1275 | FAKE_LINES="reword 1 break 2" git rebase -i HEAD~2 && |
1276 | test $colliding_sha1 = "$(git rev-parse HEAD | cut -c 1-7)" && | |
1277 | grep "^pick $colliding_sha1 " \ | |
1278 | .git/rebase-merge/git-rebase-todo.tmp && | |
1279 | grep "^pick [0-9a-f]\{40\}" \ | |
1280 | .git/rebase-merge/git-rebase-todo && | |
26027625 JS |
1281 | grep "^pick [0-9a-f]\{40\}" \ |
1282 | .git/rebase-merge/git-rebase-todo.backup && | |
b6992261 JS |
1283 | git rebase --continue |
1284 | ) && | |
1285 | collide2="$(git rev-parse HEAD~1 | cut -c 1-4)" && | |
1286 | collide3="$(git rev-parse collide3 | cut -c 1-4)" && | |
1287 | test "$collide2" = "$collide3" | |
66ae9a57 ES |
1288 | ' |
1289 | ||
edb72d55 KS |
1290 | test_expect_success 'respect core.abbrev' ' |
1291 | git config core.abbrev 12 && | |
b2dbacbd PW |
1292 | ( |
1293 | set_cat_todo_editor && | |
1294 | test_must_fail git rebase -i HEAD~4 >todo-list | |
1295 | ) && | |
edb72d55 KS |
1296 | test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list) |
1297 | ' | |
1298 | ||
28c8cfc3 ES |
1299 | test_expect_success 'todo count' ' |
1300 | write_script dump-raw.sh <<-\EOF && | |
1301 | cat "$1" | |
1302 | EOF | |
b2dbacbd PW |
1303 | ( |
1304 | test_set_editor "$(pwd)/dump-raw.sh" && | |
1305 | git rebase -i HEAD~4 >actual | |
1306 | ) && | |
b8fc9e43 | 1307 | test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual |
28c8cfc3 ES |
1308 | ' |
1309 | ||
8cbc57ca PH |
1310 | test_expect_success 'rebase -i commits that overwrite untracked files (pick)' ' |
1311 | git checkout --force branch2 && | |
1312 | git clean -f && | |
b2dbacbd PW |
1313 | ( |
1314 | set_fake_editor && | |
1315 | FAKE_LINES="edit 1 2" git rebase -i A | |
1316 | ) && | |
8cbc57ca PH |
1317 | test_cmp_rev HEAD F && |
1318 | test_path_is_missing file6 && | |
1319 | >file6 && | |
1320 | test_must_fail git rebase --continue && | |
1321 | test_cmp_rev HEAD F && | |
1322 | rm file6 && | |
1323 | git rebase --continue && | |
1324 | test_cmp_rev HEAD I | |
1325 | ' | |
1326 | ||
1327 | test_expect_success 'rebase -i commits that overwrite untracked files (squash)' ' | |
1328 | git checkout --force branch2 && | |
1329 | git clean -f && | |
1330 | git tag original-branch2 && | |
b2dbacbd PW |
1331 | ( |
1332 | set_fake_editor && | |
1333 | FAKE_LINES="edit 1 squash 2" git rebase -i A | |
1334 | ) && | |
8cbc57ca PH |
1335 | test_cmp_rev HEAD F && |
1336 | test_path_is_missing file6 && | |
1337 | >file6 && | |
1338 | test_must_fail git rebase --continue && | |
1339 | test_cmp_rev HEAD F && | |
1340 | rm file6 && | |
1341 | git rebase --continue && | |
1342 | test $(git cat-file commit HEAD | sed -ne \$p) = I && | |
1343 | git reset --hard original-branch2 | |
1344 | ' | |
1345 | ||
1346 | test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' ' | |
1347 | git checkout --force branch2 && | |
1348 | git clean -f && | |
b2dbacbd PW |
1349 | ( |
1350 | set_fake_editor && | |
1351 | FAKE_LINES="edit 1 2" git rebase -i --no-ff A | |
1352 | ) && | |
8cbc57ca PH |
1353 | test $(git cat-file commit HEAD | sed -ne \$p) = F && |
1354 | test_path_is_missing file6 && | |
1355 | >file6 && | |
1356 | test_must_fail git rebase --continue && | |
1357 | test $(git cat-file commit HEAD | sed -ne \$p) = F && | |
1358 | rm file6 && | |
1359 | git rebase --continue && | |
1360 | test $(git cat-file commit HEAD | sed -ne \$p) = I | |
1361 | ' | |
1362 | ||
0e0aff4b | 1363 | test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' ' |
d17ec3a9 JS |
1364 | git checkout -b commit-to-skip && |
1365 | for double in X 3 1 | |
1366 | do | |
1367 | test_seq 5 | sed "s/$double/&&/" >seq && | |
1368 | git add seq && | |
1369 | test_tick && | |
1370 | git commit -m seq-$double | |
1371 | done && | |
1372 | git tag seq-onto && | |
1373 | git reset --hard HEAD~2 && | |
1374 | git cherry-pick seq-onto && | |
b2dbacbd PW |
1375 | ( |
1376 | set_fake_editor && | |
1377 | test_must_fail env FAKE_LINES= git rebase -i seq-onto | |
1378 | ) && | |
d17ec3a9 JS |
1379 | test -d .git/rebase-merge && |
1380 | git rebase --continue && | |
1381 | git diff --exit-code seq-onto && | |
1382 | test ! -d .git/rebase-merge && | |
1383 | test ! -f .git/CHERRY_PICK_HEAD | |
1384 | ' | |
1385 | ||
c9266d58 GR |
1386 | rebase_setup_and_clean () { |
1387 | test_when_finished " | |
1388 | git checkout master && | |
1389 | test_might_fail git branch -D $1 && | |
1390 | test_might_fail git rebase --abort | |
1391 | " && | |
ca3e1826 | 1392 | git checkout -b $1 ${2:-master} |
c9266d58 GR |
1393 | } |
1394 | ||
1395 | test_expect_success 'drop' ' | |
1396 | rebase_setup_and_clean drop-test && | |
b2dbacbd PW |
1397 | ( |
1398 | set_fake_editor && | |
1399 | FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root | |
1400 | ) && | |
c9266d58 GR |
1401 | test E = $(git cat-file commit HEAD | sed -ne \$p) && |
1402 | test C = $(git cat-file commit HEAD^ | sed -ne \$p) && | |
1403 | test A = $(git cat-file commit HEAD^^ | sed -ne \$p) | |
1404 | ' | |
1405 | ||
37079959 GR |
1406 | test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' ' |
1407 | test_config rebase.missingCommitsCheck ignore && | |
1408 | rebase_setup_and_clean missing-commit && | |
b2dbacbd PW |
1409 | ( |
1410 | set_fake_editor && | |
1411 | FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual | |
1412 | ) && | |
37079959 | 1413 | test D = $(git cat-file commit HEAD | sed -ne \$p) && |
21d0764c JS |
1414 | test_i18ngrep \ |
1415 | "Successfully rebased and updated refs/heads/missing-commit" \ | |
1416 | actual | |
37079959 GR |
1417 | ' |
1418 | ||
37079959 | 1419 | test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' ' |
c9749b36 SG |
1420 | cat >expect <<-EOF && |
1421 | Warning: some commits may have been dropped accidentally. | |
1422 | Dropped commits (newer to older): | |
1423 | - $(git rev-list --pretty=oneline --abbrev-commit -1 master) | |
1424 | To avoid this message, use "drop" to explicitly remove a commit. | |
c9749b36 | 1425 | EOF |
37079959 GR |
1426 | test_config rebase.missingCommitsCheck warn && |
1427 | rebase_setup_and_clean missing-commit && | |
b2dbacbd PW |
1428 | ( |
1429 | set_fake_editor && | |
1430 | FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual.2 | |
1431 | ) && | |
077b9798 | 1432 | head -n4 actual.2 >actual && |
b8fc9e43 | 1433 | test_i18ncmp expect actual && |
37079959 GR |
1434 | test D = $(git cat-file commit HEAD | sed -ne \$p) |
1435 | ' | |
1436 | ||
37079959 | 1437 | test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' |
c9749b36 SG |
1438 | cat >expect <<-EOF && |
1439 | Warning: some commits may have been dropped accidentally. | |
1440 | Dropped commits (newer to older): | |
1441 | - $(git rev-list --pretty=oneline --abbrev-commit -1 master) | |
1442 | - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2) | |
1443 | To avoid this message, use "drop" to explicitly remove a commit. | |
1444 | ||
1445 | Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings. | |
1446 | The possible behaviours are: ignore, warn, error. | |
1447 | ||
1448 | You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''. | |
1449 | Or you can abort the rebase with '\''git rebase --abort'\''. | |
1450 | EOF | |
37079959 GR |
1451 | test_config rebase.missingCommitsCheck error && |
1452 | rebase_setup_and_clean missing-commit && | |
b2dbacbd PW |
1453 | ( |
1454 | set_fake_editor && | |
1455 | test_must_fail env FAKE_LINES="1 2 4" \ | |
1456 | git rebase -i --root 2>actual && | |
1457 | test_i18ncmp expect actual && | |
1458 | cp .git/rebase-merge/git-rebase-todo.backup \ | |
1459 | .git/rebase-merge/git-rebase-todo && | |
1460 | FAKE_LINES="1 2 drop 3 4 drop 5" git rebase --edit-todo | |
1461 | ) && | |
37079959 GR |
1462 | git rebase --continue && |
1463 | test D = $(git cat-file commit HEAD | sed -ne \$p) && | |
1464 | test B = $(git cat-file commit HEAD^ | sed -ne \$p) | |
1465 | ' | |
1466 | ||
5a5445d8 AG |
1467 | test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ignore' ' |
1468 | test_config rebase.missingCommitsCheck ignore && | |
1469 | rebase_setup_and_clean missing-commit && | |
1470 | ( | |
1471 | set_fake_editor && | |
1472 | FAKE_LINES="break 1 2 3 4 5" git rebase -i --root && | |
1473 | FAKE_LINES="1 2 3 4" git rebase --edit-todo && | |
1474 | git rebase --continue 2>actual | |
1475 | ) && | |
1476 | test D = $(git cat-file commit HEAD | sed -ne \$p) && | |
1477 | test_i18ngrep \ | |
1478 | "Successfully rebased and updated refs/heads/missing-commit" \ | |
1479 | actual | |
1480 | ' | |
1481 | ||
1482 | test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' ' | |
1483 | cat >expect <<-EOF && | |
1484 | error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) | |
1485 | Warning: some commits may have been dropped accidentally. | |
1486 | Dropped commits (newer to older): | |
1487 | - $(git rev-list --pretty=oneline --abbrev-commit -1 master) | |
1488 | - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) | |
1489 | To avoid this message, use "drop" to explicitly remove a commit. | |
1490 | EOF | |
1491 | head -n4 expect >expect.2 && | |
1492 | tail -n1 expect >>expect.2 && | |
1493 | tail -n4 expect.2 >expect.3 && | |
1494 | test_config rebase.missingCommitsCheck warn && | |
1495 | rebase_setup_and_clean missing-commit && | |
1496 | ( | |
1497 | set_fake_editor && | |
1498 | test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \ | |
1499 | git rebase -i --root && | |
1500 | cp .git/rebase-merge/git-rebase-todo.backup orig && | |
1501 | FAKE_LINES="2 3 4" git rebase --edit-todo 2>actual.2 && | |
1502 | head -n6 actual.2 >actual && | |
1503 | test_i18ncmp expect actual && | |
1504 | cp orig .git/rebase-merge/git-rebase-todo && | |
1505 | FAKE_LINES="1 2 3 4" git rebase --edit-todo 2>actual.2 && | |
1506 | head -n4 actual.2 >actual && | |
1507 | test_i18ncmp expect.3 actual && | |
1508 | git rebase --continue 2>actual | |
1509 | ) && | |
1510 | test D = $(git cat-file commit HEAD | sed -ne \$p) && | |
1511 | test_i18ngrep \ | |
1512 | "Successfully rebased and updated refs/heads/missing-commit" \ | |
1513 | actual | |
1514 | ' | |
1515 | ||
1516 | test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' ' | |
1517 | cat >expect <<-EOF && | |
1518 | error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) | |
1519 | Warning: some commits may have been dropped accidentally. | |
1520 | Dropped commits (newer to older): | |
1521 | - $(git rev-list --pretty=oneline --abbrev-commit -1 master) | |
1522 | - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) | |
1523 | To avoid this message, use "drop" to explicitly remove a commit. | |
1524 | ||
1525 | Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings. | |
1526 | The possible behaviours are: ignore, warn, error. | |
1527 | ||
1528 | You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''. | |
1529 | Or you can abort the rebase with '\''git rebase --abort'\''. | |
1530 | EOF | |
1531 | tail -n11 expect >expect.2 && | |
1532 | head -n3 expect.2 >expect.3 && | |
1533 | tail -n7 expect.2 >>expect.3 && | |
1534 | test_config rebase.missingCommitsCheck error && | |
1535 | rebase_setup_and_clean missing-commit && | |
1536 | ( | |
1537 | set_fake_editor && | |
1538 | test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \ | |
1539 | git rebase -i --root && | |
1540 | cp .git/rebase-merge/git-rebase-todo.backup orig && | |
1541 | test_must_fail env FAKE_LINES="2 3 4" \ | |
1542 | git rebase --edit-todo 2>actual && | |
1543 | test_i18ncmp expect actual && | |
1544 | test_must_fail git rebase --continue 2>actual && | |
1545 | test_i18ncmp expect.2 actual && | |
1546 | test_must_fail git rebase --edit-todo && | |
1547 | cp orig .git/rebase-merge/git-rebase-todo && | |
1548 | test_must_fail env FAKE_LINES="1 2 3 4" \ | |
1549 | git rebase --edit-todo 2>actual && | |
1550 | test_i18ncmp expect.3 actual && | |
1551 | test_must_fail git rebase --continue 2>actual && | |
1552 | test_i18ncmp expect.3 actual && | |
1553 | cp orig .git/rebase-merge/git-rebase-todo && | |
1554 | FAKE_LINES="1 2 3 4 drop 5" git rebase --edit-todo && | |
1555 | git rebase --continue 2>actual | |
1556 | ) && | |
1557 | test D = $(git cat-file commit HEAD | sed -ne \$p) && | |
1558 | test_i18ngrep \ | |
1559 | "Successfully rebased and updated refs/heads/missing-commit" \ | |
1560 | actual | |
1561 | ' | |
1562 | ||
1563 | test_expect_success 'rebase.missingCommitsCheck = error after resolving conflicts' ' | |
1564 | test_config rebase.missingCommitsCheck error && | |
1565 | ( | |
1566 | set_fake_editor && | |
1567 | FAKE_LINES="drop 1 break 2 3 4" git rebase -i A E | |
1568 | ) && | |
1569 | git rebase --edit-todo && | |
1570 | test_must_fail git rebase --continue && | |
1571 | echo x >file1 && | |
1572 | git add file1 && | |
1573 | git rebase --continue | |
1574 | ' | |
1575 | ||
1576 | test_expect_success 'rebase.missingCommitsCheck = error when editing for a second time' ' | |
1577 | test_config rebase.missingCommitsCheck error && | |
1578 | ( | |
1579 | set_fake_editor && | |
1580 | FAKE_LINES="1 break 2 3" git rebase -i A D && | |
1581 | cp .git/rebase-merge/git-rebase-todo todo && | |
1582 | test_must_fail env FAKE_LINES=2 git rebase --edit-todo && | |
1583 | GIT_SEQUENCE_EDITOR="cp todo" git rebase --edit-todo && | |
1584 | git rebase --continue | |
1585 | ) | |
1586 | ' | |
1587 | ||
17959934 LB |
1588 | test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' ' |
1589 | rebase_setup_and_clean abbrevcmd && | |
1590 | test_commit "first" file1.txt "first line" first && | |
1591 | test_commit "second" file1.txt "another line" second && | |
1592 | test_commit "fixup! first" file2.txt "first line again" first_fixup && | |
1593 | test_commit "squash! second" file1.txt "another line here" second_squash && | |
1594 | cat >expected <<-EOF && | |
1595 | p $(git rev-list --abbrev-commit -1 first) first | |
1596 | f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first | |
1597 | x git show HEAD | |
1598 | p $(git rev-list --abbrev-commit -1 second) second | |
1599 | s $(git rev-list --abbrev-commit -1 second_squash) squash! second | |
1600 | x git show HEAD | |
1601 | EOF | |
1602 | git checkout abbrevcmd && | |
17959934 | 1603 | test_config rebase.abbreviateCommands true && |
b2dbacbd PW |
1604 | ( |
1605 | set_cat_todo_editor && | |
1606 | test_must_fail git rebase -i --exec "git show HEAD" \ | |
1607 | --autosquash master >actual | |
1608 | ) && | |
17959934 LB |
1609 | test_cmp expected actual |
1610 | ' | |
1611 | ||
804098bb GR |
1612 | test_expect_success 'static check of bad command' ' |
1613 | rebase_setup_and_clean bad-cmd && | |
b2dbacbd PW |
1614 | ( |
1615 | set_fake_editor && | |
1616 | test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \ | |
804098bb | 1617 | git rebase -i --root 2>actual && |
b2dbacbd PW |
1618 | test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" \ |
1619 | actual && | |
1620 | test_i18ngrep "You can fix this with .git rebase --edit-todo.." \ | |
1621 | actual && | |
1622 | FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo | |
1623 | ) && | |
804098bb GR |
1624 | git rebase --continue && |
1625 | test E = $(git cat-file commit HEAD | sed -ne \$p) && | |
1626 | test C = $(git cat-file commit HEAD^ | sed -ne \$p) | |
1627 | ' | |
1628 | ||
1db168ee MM |
1629 | test_expect_success 'tabs and spaces are accepted in the todolist' ' |
1630 | rebase_setup_and_clean indented-comment && | |
1631 | write_script add-indent.sh <<-\EOF && | |
1632 | ( | |
1633 | # Turn single spaces into space/tab mix | |
1634 | sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1" | |
1635 | printf "\n\t# comment\n #more\n\t # comment\n" | |
7966230b | 1636 | ) >"$1.new" |
1db168ee MM |
1637 | mv "$1.new" "$1" |
1638 | EOF | |
b2dbacbd PW |
1639 | ( |
1640 | test_set_editor "$(pwd)/add-indent.sh" && | |
1641 | git rebase -i HEAD^^^ | |
1642 | ) && | |
1db168ee MM |
1643 | test E = $(git cat-file commit HEAD | sed -ne \$p) |
1644 | ' | |
1645 | ||
804098bb GR |
1646 | test_expect_success 'static check of bad SHA-1' ' |
1647 | rebase_setup_and_clean bad-sha && | |
b2dbacbd PW |
1648 | ( |
1649 | set_fake_editor && | |
1650 | test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \ | |
1651 | git rebase -i --root 2>actual && | |
1652 | test_i18ngrep "edit XXXXXXX False commit" actual && | |
1653 | test_i18ngrep "You can fix this with .git rebase --edit-todo.." \ | |
1654 | actual && | |
1655 | FAKE_LINES="1 2 4 5 6" git rebase --edit-todo | |
1656 | ) && | |
804098bb GR |
1657 | git rebase --continue && |
1658 | test E = $(git cat-file commit HEAD | sed -ne \$p) | |
1659 | ' | |
1660 | ||
39743cf5 | 1661 | test_expect_success 'editor saves as CR/LF' ' |
1db25aae JS |
1662 | git checkout -b with-crlf && |
1663 | write_script add-crs.sh <<-\EOF && | |
1664 | sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new && | |
1665 | mv -f "$1".new "$1" | |
1666 | EOF | |
1667 | ( | |
1668 | test_set_editor "$(pwd)/add-crs.sh" && | |
1669 | git rebase -i HEAD^ | |
1670 | ) | |
1671 | ' | |
1672 | ||
6672b9f9 | 1673 | test_expect_success 'rebase -i --gpg-sign=<key-id>' ' |
ed1e5282 | 1674 | test_when_finished "test_might_fail git rebase --abort" && |
b2dbacbd PW |
1675 | ( |
1676 | set_fake_editor && | |
1677 | FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \ | |
1678 | HEAD^ >out 2>err | |
1679 | ) && | |
ed1e5282 JS |
1680 | test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err |
1681 | ' | |
1682 | ||
1683 | test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' ' | |
1684 | test_when_finished "test_might_fail git rebase --abort" && | |
1685 | test_config commit.gpgsign true && | |
b2dbacbd PW |
1686 | ( |
1687 | set_fake_editor && | |
1688 | FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \ | |
1689 | HEAD^ >out 2>err | |
1690 | ) && | |
7ca79dca | 1691 | test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err |
6672b9f9 JS |
1692 | ' |
1693 | ||
ca3e1826 ES |
1694 | test_expect_success 'valid author header after --root swap' ' |
1695 | rebase_setup_and_clean author-header no-conflict-branch && | |
4aa5ff94 PW |
1696 | git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit && |
1697 | git cat-file commit HEAD | grep ^author >expected && | |
b2dbacbd PW |
1698 | ( |
1699 | set_fake_editor && | |
1700 | FAKE_LINES="5 1" git rebase -i --root | |
1701 | ) && | |
4aa5ff94 PW |
1702 | git cat-file commit HEAD^ | grep ^author >actual && |
1703 | test_cmp expected actual | |
1704 | ' | |
1705 | ||
1706 | test_expect_success 'valid author header when author contains single quote' ' | |
1707 | rebase_setup_and_clean author-header no-conflict-branch && | |
4aa5ff94 PW |
1708 | git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit && |
1709 | git cat-file commit HEAD | grep ^author >expected && | |
b2dbacbd PW |
1710 | ( |
1711 | set_fake_editor && | |
1712 | FAKE_LINES="2" git rebase -i HEAD~2 | |
1713 | ) && | |
4aa5ff94 PW |
1714 | git cat-file commit HEAD | grep ^author >actual && |
1715 | test_cmp expected actual | |
ca3e1826 ES |
1716 | ' |
1717 | ||
4627bc77 PW |
1718 | test_expect_success 'post-commit hook is called' ' |
1719 | test_when_finished "rm -f .git/hooks/post-commit" && | |
1720 | >actual && | |
1721 | mkdir -p .git/hooks && | |
1722 | write_script .git/hooks/post-commit <<-\EOS && | |
1723 | git rev-parse HEAD >>actual | |
1724 | EOS | |
1725 | ( | |
1726 | set_fake_editor && | |
1727 | FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E && | |
1728 | echo x>file3 && | |
1729 | git add file3 && | |
1730 | FAKE_COMMIT_MESSAGE=edited git rebase --continue | |
1731 | ) && | |
1732 | git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \ | |
1733 | >expect && | |
1734 | test_cmp expect actual | |
1735 | ' | |
1736 | ||
430b75f7 PW |
1737 | test_expect_success 'correct error message for partial commit after empty pick' ' |
1738 | test_when_finished "git rebase --abort" && | |
1739 | ( | |
1740 | set_fake_editor && | |
1741 | FAKE_LINES="2 1 1" && | |
1742 | export FAKE_LINES && | |
1743 | test_must_fail git rebase -i A D | |
1744 | ) && | |
1745 | echo x >file1 && | |
1746 | test_must_fail git commit file1 2>err && | |
1747 | test_i18ngrep "cannot do a partial commit during a rebase." err | |
1748 | ' | |
1749 | ||
1750 | test_expect_success 'correct error message for commit --amend after empty pick' ' | |
1751 | test_when_finished "git rebase --abort" && | |
1752 | ( | |
1753 | set_fake_editor && | |
1754 | FAKE_LINES="1 1" && | |
1755 | export FAKE_LINES && | |
1756 | test_must_fail git rebase -i A D | |
1757 | ) && | |
1758 | echo x>file1 && | |
1759 | test_must_fail git commit -a --amend 2>err && | |
1760 | test_i18ngrep "middle of a rebase -- cannot amend." err | |
1761 | ' | |
1762 | ||
6a619ca0 PW |
1763 | # This must be the last test in this file |
1764 | test_expect_success '$EDITOR and friends are unchanged' ' | |
1765 | test_editor_unchanged | |
1766 | ' | |
1767 | ||
1b1dce4b | 1768 | test_done |