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