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