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