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