git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
git / t / t3404-rebase-interactive.sh
| 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. |
| 10 | |
| 11 | Initial setup: |
| 12 | |
| 13 | one - two - three - four (conflict-branch) |
| 14 | / |
| 15 | A - B - C - D - E (primary) |
| 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". |
| 27 | ' |
| 28 | |
| 29 | . ./test-lib.sh |
| 30 | |
| 31 | . "$TEST_DIRECTORY"/lib-rebase.sh |
| 32 | |
| 33 | test_expect_success 'setup' ' |
| 34 | # Commit dates are hardcoded to 2005, and the reflog entries will have |
| 35 | # a matching timestamp. Maintenance may thus immediately expire |
| 36 | # reflogs if it was running. |
| 37 | git config set gc.reflogExpire never && |
| 38 | git config set gc.reflogExpireUnreachable never && |
| 39 | |
| 40 | git switch -C primary && |
| 41 | test_commit A file1 && |
| 42 | test_commit B file1 && |
| 43 | test_commit C file2 && |
| 44 | test_commit D file1 && |
| 45 | test_commit E file3 && |
| 46 | git checkout -b branch1 A && |
| 47 | test_commit F file4 && |
| 48 | test_commit G file1 && |
| 49 | test_commit H file5 && |
| 50 | git checkout -b branch2 F && |
| 51 | test_commit I file6 && |
| 52 | git checkout -b conflict-branch A && |
| 53 | test_commit one conflict && |
| 54 | test_commit two conflict && |
| 55 | test_commit three conflict && |
| 56 | test_commit four conflict && |
| 57 | git checkout -b no-conflict-branch A && |
| 58 | test_commit J fileJ && |
| 59 | test_commit K fileK && |
| 60 | test_commit L fileL && |
| 61 | test_commit M fileM && |
| 62 | git checkout -b no-ff-branch A && |
| 63 | test_commit N fileN && |
| 64 | test_commit O fileO && |
| 65 | test_commit P fileP |
| 66 | ' |
| 67 | |
| 68 | test_expect_success MINGW 'rebase releases object database before committing' ' |
| 69 | test_when_finished "rm -f .git/hooks/post-commit repacked packs" && |
| 70 | git switch -C repack-rewrite primary && |
| 71 | git repack -ad && |
| 72 | write_script .git/hooks/post-commit <<-\EOF && |
| 73 | git repack -ad && |
| 74 | >repacked |
| 75 | EOF |
| 76 | ( |
| 77 | set_fake_editor && |
| 78 | FAKE_LINES="reword 1" GIT_TEST_LEGACY_DELETE=1 \ |
| 79 | git -c core.commitGraph=false rebase -i HEAD^ |
| 80 | ) && |
| 81 | test_path_is_file repacked && |
| 82 | ls .git/objects/pack/*.pack >packs && |
| 83 | test_line_count = 1 packs |
| 84 | ' |
| 85 | |
| 86 | # "exec" commands are run with the user shell by default, but this may |
| 87 | # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work |
| 88 | # to create a file. Unsetting SHELL avoids such non-portable behavior |
| 89 | # in tests. It must be exported for it to take effect where needed. |
| 90 | SHELL= |
| 91 | export SHELL |
| 92 | |
| 93 | test_expect_success 'rebase --keep-empty' ' |
| 94 | git checkout -b emptybranch primary && |
| 95 | git commit --allow-empty -m "empty" && |
| 96 | git rebase --keep-empty -i HEAD~2 && |
| 97 | git log --oneline >actual && |
| 98 | test_line_count = 6 actual |
| 99 | ' |
| 100 | |
| 101 | test_expect_success 'rebase -i with empty todo list' ' |
| 102 | cat >expect <<-\EOF && |
| 103 | error: nothing to do |
| 104 | EOF |
| 105 | ( |
| 106 | set_fake_editor && |
| 107 | test_must_fail env FAKE_LINES="#" \ |
| 108 | git rebase -i HEAD^ >output 2>&1 |
| 109 | ) && |
| 110 | tail -n 1 output >actual && # Ignore output about changing todo list |
| 111 | test_cmp expect actual |
| 112 | ' |
| 113 | |
| 114 | test_expect_success 'rebase -i with the exec command' ' |
| 115 | git checkout primary && |
| 116 | ( |
| 117 | set_fake_editor && |
| 118 | FAKE_LINES="1 exec_>touch-one |
| 119 | 2 exec_>touch-two exec_false exec_>touch-three |
| 120 | 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" && |
| 121 | export FAKE_LINES && |
| 122 | test_must_fail git rebase -i A |
| 123 | ) && |
| 124 | test_path_is_file touch-one && |
| 125 | test_path_is_file touch-two && |
| 126 | # Missing because we should have stopped by now. |
| 127 | test_path_is_missing touch-three && |
| 128 | test_cmp_rev C HEAD && |
| 129 | git rebase --continue && |
| 130 | test_path_is_file touch-three && |
| 131 | test_path_is_file "touch-file name with spaces" && |
| 132 | test_path_is_file touch-after-semicolon && |
| 133 | test_cmp_rev primary HEAD && |
| 134 | rm -f touch-* |
| 135 | ' |
| 136 | |
| 137 | test_expect_success 'rebase -i with the exec command runs from tree root' ' |
| 138 | git checkout primary && |
| 139 | mkdir subdir && (cd subdir && |
| 140 | set_fake_editor && |
| 141 | FAKE_LINES="1 exec_>touch-subdir" \ |
| 142 | git rebase -i HEAD^ |
| 143 | ) && |
| 144 | test_path_is_file touch-subdir && |
| 145 | rm -fr subdir |
| 146 | ' |
| 147 | |
| 148 | test_expect_success 'rebase -i with exec allows git commands in subdirs' ' |
| 149 | test_when_finished "rm -rf subdir" && |
| 150 | test_when_finished "git rebase --abort ||:" && |
| 151 | git checkout primary && |
| 152 | mkdir subdir && (cd subdir && |
| 153 | set_fake_editor && |
| 154 | FAKE_LINES="1 x_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \ |
| 155 | git rebase -i HEAD^ |
| 156 | ) |
| 157 | ' |
| 158 | |
| 159 | test_expect_success 'rebase -i sets work tree properly' ' |
| 160 | test_when_finished "rm -rf subdir" && |
| 161 | test_when_finished "test_might_fail git rebase --abort" && |
| 162 | mkdir subdir && |
| 163 | git rebase -x "(cd subdir && git rev-parse --show-toplevel)" HEAD^ \ |
| 164 | >actual && |
| 165 | test_grep ! "/subdir$" actual |
| 166 | ' |
| 167 | |
| 168 | test_expect_success 'rebase -i with the exec command checks tree cleanness' ' |
| 169 | git checkout primary && |
| 170 | ( |
| 171 | set_fake_editor && |
| 172 | test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" \ |
| 173 | git rebase -i HEAD^ |
| 174 | ) && |
| 175 | test_cmp_rev primary^ HEAD && |
| 176 | git reset --hard && |
| 177 | git rebase --continue |
| 178 | ' |
| 179 | |
| 180 | test_expect_success 'cherry-pick works with rebase --exec' ' |
| 181 | test_when_finished "git cherry-pick --abort; \ |
| 182 | git rebase --abort; \ |
| 183 | git checkout primary" && |
| 184 | echo "exec git cherry-pick G" >todo && |
| 185 | ( |
| 186 | set_replace_editor todo && |
| 187 | test_must_fail git rebase -i D D |
| 188 | ) && |
| 189 | test_cmp_rev G CHERRY_PICK_HEAD |
| 190 | ' |
| 191 | |
| 192 | test_expect_success 'rebase -x with empty command fails' ' |
| 193 | test_when_finished "git rebase --abort ||:" && |
| 194 | test_must_fail env git rebase -x "" @ 2>actual && |
| 195 | test_write_lines "error: empty exec command" >expected && |
| 196 | test_cmp expected actual && |
| 197 | test_must_fail env git rebase -x " " @ 2>actual && |
| 198 | test_cmp expected actual |
| 199 | ' |
| 200 | |
| 201 | test_expect_success 'rebase -x with newline in command fails' ' |
| 202 | test_when_finished "git rebase --abort ||:" && |
| 203 | test_must_fail env git rebase -x "a${LF}b" @ 2>actual && |
| 204 | test_write_lines "error: exec commands cannot contain newlines" \ |
| 205 | >expected && |
| 206 | test_cmp expected actual |
| 207 | ' |
| 208 | |
| 209 | test_expect_success 'rebase -i with exec of inexistent command' ' |
| 210 | git checkout primary && |
| 211 | test_when_finished "git rebase --abort" && |
| 212 | ( |
| 213 | set_fake_editor && |
| 214 | test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \ |
| 215 | git rebase -i HEAD^ >actual 2>&1 |
| 216 | ) && |
| 217 | test_grep ! "Maybe git-rebase is broken" actual |
| 218 | ' |
| 219 | |
| 220 | test_expect_success 'implicit interactive rebase does not invoke sequence editor' ' |
| 221 | test_when_finished "git rebase --abort ||:" && |
| 222 | GIT_SEQUENCE_EDITOR="echo bad >" git rebase -x"echo one" @^ |
| 223 | ' |
| 224 | |
| 225 | test_expect_success 'no changes are a nop' ' |
| 226 | git checkout branch2 && |
| 227 | git rebase -i F && |
| 228 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && |
| 229 | test_cmp_rev I HEAD |
| 230 | ' |
| 231 | |
| 232 | test_expect_success 'test the [branch] option' ' |
| 233 | git checkout -b dead-end && |
| 234 | git rm file6 && |
| 235 | git commit -m "stop here" && |
| 236 | git rebase -i F branch2 && |
| 237 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && |
| 238 | test_cmp_rev I branch2 && |
| 239 | test_cmp_rev I HEAD |
| 240 | ' |
| 241 | |
| 242 | test_expect_success 'test --onto <branch>' ' |
| 243 | git checkout -b test-onto branch2 && |
| 244 | git rebase -i --onto branch1 F && |
| 245 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" && |
| 246 | test_cmp_rev HEAD^ branch1 && |
| 247 | test_cmp_rev I branch2 |
| 248 | ' |
| 249 | |
| 250 | test_expect_success 'rebase on top of a non-conflicting commit' ' |
| 251 | git checkout branch1 && |
| 252 | git tag original-branch1 && |
| 253 | git rebase -i branch2 && |
| 254 | test file6 = $(git diff --name-only original-branch1) && |
| 255 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" && |
| 256 | test_cmp_rev I branch2 && |
| 257 | test_cmp_rev I HEAD~2 |
| 258 | ' |
| 259 | |
| 260 | test_expect_success 'reflog for the branch shows state before rebase' ' |
| 261 | test_cmp_rev branch1@{1} original-branch1 |
| 262 | ' |
| 263 | |
| 264 | test_expect_success 'reflog for the branch shows correct finish message' ' |
| 265 | printf "rebase (finish): refs/heads/branch1 onto %s\n" \ |
| 266 | "$(git rev-parse branch2)" >expected && |
| 267 | git log -g --pretty=%gs -1 refs/heads/branch1 >actual && |
| 268 | test_cmp expected actual |
| 269 | ' |
| 270 | |
| 271 | test_expect_success 'exchange two commits' ' |
| 272 | ( |
| 273 | set_fake_editor && |
| 274 | FAKE_LINES="2 1" git rebase -i HEAD~2 |
| 275 | ) && |
| 276 | test H = $(git cat-file commit HEAD^ | sed -ne \$p) && |
| 277 | test G = $(git cat-file commit HEAD | sed -ne \$p) && |
| 278 | blob1=$(git rev-parse --short HEAD^:file1) && |
| 279 | blob2=$(git rev-parse --short HEAD:file1) && |
| 280 | commit=$(git rev-parse --short HEAD) |
| 281 | ' |
| 282 | |
| 283 | test_expect_success 'stop on conflicting pick' ' |
| 284 | cat >expect <<-EOF && |
| 285 | diff --git a/file1 b/file1 |
| 286 | index $blob1..$blob2 100644 |
| 287 | --- a/file1 |
| 288 | +++ b/file1 |
| 289 | @@ -1 +1 @@ |
| 290 | -A |
| 291 | +G |
| 292 | EOF |
| 293 | cat >expect2 <<-EOF && |
| 294 | <<<<<<< HEAD |
| 295 | D |
| 296 | ======= |
| 297 | G |
| 298 | >>>>>>> $commit (G) |
| 299 | EOF |
| 300 | git tag new-branch1 && |
| 301 | test_must_fail git rebase -i primary && |
| 302 | test "$(git rev-parse HEAD~3)" = "$(git rev-parse primary)" && |
| 303 | test_cmp expect .git/rebase-merge/patch && |
| 304 | test_cmp expect2 file1 && |
| 305 | test "$(git diff --name-status | |
| 306 | sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 && |
| 307 | grep -v "^#" <.git/rebase-merge/done >actual && |
| 308 | test_line_count = 4 actual && |
| 309 | test 0 = $(grep -c "^[^#]" <.git/rebase-merge/git-rebase-todo) |
| 310 | ' |
| 311 | |
| 312 | test_expect_success 'show conflicted patch' ' |
| 313 | GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr && |
| 314 | test_grep "show.*REBASE_HEAD" stderr && |
| 315 | # the original stopped-sha1 is abbreviated |
| 316 | stopped_sha1="$(git rev-parse $(cat ".git/rebase-merge/stopped-sha"))" && |
| 317 | test "$(git rev-parse REBASE_HEAD)" = "$stopped_sha1" |
| 318 | ' |
| 319 | |
| 320 | test_expect_success 'abort' ' |
| 321 | git rebase --abort && |
| 322 | test_cmp_rev new-branch1 HEAD && |
| 323 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" && |
| 324 | test_path_is_missing .git/rebase-merge |
| 325 | ' |
| 326 | |
| 327 | test_expect_success 'abort with error when new base cannot be checked out' ' |
| 328 | git rm --cached file1 && |
| 329 | git commit -m "remove file in base" && |
| 330 | test_must_fail git rebase -i primary > output 2>&1 && |
| 331 | test_grep "The following untracked working tree files would be overwritten by checkout:" \ |
| 332 | output && |
| 333 | test_grep "file1" output && |
| 334 | test_path_is_missing .git/rebase-merge && |
| 335 | rm file1 && |
| 336 | git reset --hard HEAD^ |
| 337 | ' |
| 338 | |
| 339 | test_expect_success 'retain authorship' ' |
| 340 | echo A > file7 && |
| 341 | git add file7 && |
| 342 | test_tick && |
| 343 | GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && |
| 344 | git tag twerp && |
| 345 | git rebase -i --onto primary HEAD^ && |
| 346 | git show HEAD >actual && |
| 347 | test_grep "^Author: Twerp Snog" actual |
| 348 | ' |
| 349 | |
| 350 | test_expect_success 'retain authorship w/ conflicts' ' |
| 351 | oGIT_AUTHOR_NAME=$GIT_AUTHOR_NAME && |
| 352 | test_when_finished "GIT_AUTHOR_NAME=\$oGIT_AUTHOR_NAME" && |
| 353 | |
| 354 | git reset --hard twerp && |
| 355 | test_commit a conflict a conflict-a && |
| 356 | git reset --hard twerp && |
| 357 | |
| 358 | GIT_AUTHOR_NAME=AttributeMe && |
| 359 | export GIT_AUTHOR_NAME && |
| 360 | test_commit b conflict b conflict-b && |
| 361 | GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME && |
| 362 | |
| 363 | test_must_fail git rebase -i conflict-a && |
| 364 | echo resolved >conflict && |
| 365 | git add conflict && |
| 366 | git rebase --continue && |
| 367 | test_cmp_rev conflict-a^0 HEAD^ && |
| 368 | git show >out && |
| 369 | test_grep AttributeMe out |
| 370 | ' |
| 371 | |
| 372 | test_expect_success 'squash' ' |
| 373 | git reset --hard twerp && |
| 374 | echo B > file7 && |
| 375 | test_tick && |
| 376 | GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 && |
| 377 | echo "******************************" && |
| 378 | ( |
| 379 | set_fake_editor && |
| 380 | FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \ |
| 381 | git rebase -i --onto primary HEAD~2 |
| 382 | ) && |
| 383 | test B = $(cat file7) && |
| 384 | test_cmp_rev HEAD^ primary |
| 385 | ' |
| 386 | |
| 387 | test_expect_success 'retain authorship when squashing' ' |
| 388 | git show HEAD >actual && |
| 389 | test_grep "^Author: Twerp Snog" actual |
| 390 | ' |
| 391 | |
| 392 | test_expect_success '--continue tries to commit' ' |
| 393 | git reset --hard D && |
| 394 | test_tick && |
| 395 | ( |
| 396 | set_fake_editor && |
| 397 | test_must_fail git rebase -i --onto new-branch1 HEAD^ && |
| 398 | echo resolved > file1 && |
| 399 | git add file1 && |
| 400 | FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue |
| 401 | ) && |
| 402 | test_cmp_rev HEAD^ new-branch1 && |
| 403 | git show HEAD >actual && |
| 404 | test_grep chouette actual |
| 405 | ' |
| 406 | |
| 407 | test_expect_success 'verbose flag is heeded, even after --continue' ' |
| 408 | git reset --hard primary@{1} && |
| 409 | test_tick && |
| 410 | test_must_fail git rebase -v -i --onto new-branch1 HEAD^ && |
| 411 | echo resolved > file1 && |
| 412 | git add file1 && |
| 413 | git rebase --continue > output && |
| 414 | test_grep "^ file1 | 2 +-$" output |
| 415 | ' |
| 416 | |
| 417 | test_expect_success 'multi-squash only fires up editor once' ' |
| 418 | base=$(git rev-parse HEAD~4) && |
| 419 | ( |
| 420 | set_fake_editor && |
| 421 | FAKE_COMMIT_AMEND="ONCE" \ |
| 422 | FAKE_LINES="1 squash 2 squash 3 squash 4" \ |
| 423 | EXPECT_HEADER_COUNT=4 \ |
| 424 | git rebase -i $base |
| 425 | ) && |
| 426 | test $base = $(git rev-parse HEAD^) && |
| 427 | git show >output && |
| 428 | grep ONCE output >actual && |
| 429 | test_line_count = 1 actual |
| 430 | ' |
| 431 | |
| 432 | test_expect_success 'multi-fixup does not fire up editor' ' |
| 433 | git checkout -b multi-fixup E && |
| 434 | base=$(git rev-parse HEAD~4) && |
| 435 | ( |
| 436 | set_fake_editor && |
| 437 | FAKE_COMMIT_AMEND="NEVER" \ |
| 438 | FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ |
| 439 | git rebase -i $base |
| 440 | ) && |
| 441 | test $base = $(git rev-parse HEAD^) && |
| 442 | git show >output && |
| 443 | test_grep ! NEVER output && |
| 444 | git checkout @{-1} && |
| 445 | git branch -D multi-fixup |
| 446 | ' |
| 447 | |
| 448 | test_expect_success 'commit message used after conflict' ' |
| 449 | git checkout -b conflict-fixup conflict-branch && |
| 450 | base=$(git rev-parse HEAD~4) && |
| 451 | ( |
| 452 | set_fake_editor && |
| 453 | test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" \ |
| 454 | git rebase -i $base && |
| 455 | echo three > conflict && |
| 456 | git add conflict && |
| 457 | FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \ |
| 458 | git rebase --continue |
| 459 | ) && |
| 460 | test $base = $(git rev-parse HEAD^) && |
| 461 | git show >output && |
| 462 | grep ONCE output >actual && |
| 463 | test_line_count = 1 actual && |
| 464 | git checkout @{-1} && |
| 465 | git branch -D conflict-fixup |
| 466 | ' |
| 467 | |
| 468 | test_expect_success 'commit message retained after conflict' ' |
| 469 | git checkout -b conflict-squash conflict-branch && |
| 470 | base=$(git rev-parse HEAD~4) && |
| 471 | ( |
| 472 | set_fake_editor && |
| 473 | test_must_fail env FAKE_LINES="1 fixup 3 squash 4" \ |
| 474 | git rebase -i $base && |
| 475 | echo three > conflict && |
| 476 | git add conflict && |
| 477 | FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \ |
| 478 | git rebase --continue |
| 479 | ) && |
| 480 | test $base = $(git rev-parse HEAD^) && |
| 481 | git show >output && |
| 482 | grep TWICE output >actual && |
| 483 | test_line_count = 2 actual && |
| 484 | git checkout @{-1} && |
| 485 | git branch -D conflict-squash |
| 486 | ' |
| 487 | |
| 488 | test_expect_success 'squash and fixup generate correct log messages' ' |
| 489 | cat >expect-squash-fixup <<-\EOF && |
| 490 | B |
| 491 | |
| 492 | D |
| 493 | |
| 494 | ONCE |
| 495 | EOF |
| 496 | git checkout -b squash-fixup E && |
| 497 | base=$(git rev-parse HEAD~4) && |
| 498 | ( |
| 499 | set_fake_editor && |
| 500 | FAKE_COMMIT_AMEND="ONCE" \ |
| 501 | FAKE_LINES="1 fixup 2 squash 3 fixup 4" \ |
| 502 | EXPECT_HEADER_COUNT=4 \ |
| 503 | git rebase -i $base |
| 504 | ) && |
| 505 | commit_body HEAD >actual-squash-fixup && |
| 506 | test_cmp expect-squash-fixup actual-squash-fixup && |
| 507 | git cat-file commit HEAD@{2} >actual && |
| 508 | test_grep "^# This is a combination of 3 commits\." actual && |
| 509 | git cat-file commit HEAD@{3} >actual && |
| 510 | test_grep "^# This is a combination of 2 commits\." actual && |
| 511 | git checkout @{-1} && |
| 512 | git branch -D squash-fixup |
| 513 | ' |
| 514 | |
| 515 | test_expect_success 'squash ignores comments' ' |
| 516 | git checkout -b skip-comments E && |
| 517 | base=$(git rev-parse HEAD~4) && |
| 518 | ( |
| 519 | set_fake_editor && |
| 520 | FAKE_COMMIT_AMEND="ONCE" \ |
| 521 | FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \ |
| 522 | EXPECT_HEADER_COUNT=4 \ |
| 523 | git rebase -i $base |
| 524 | ) && |
| 525 | test $base = $(git rev-parse HEAD^) && |
| 526 | git show >output && |
| 527 | grep ONCE output >actual && |
| 528 | test_line_count = 1 actual && |
| 529 | git checkout @{-1} && |
| 530 | git branch -D skip-comments |
| 531 | ' |
| 532 | |
| 533 | test_expect_success 'squash ignores blank lines' ' |
| 534 | git checkout -b skip-blank-lines E && |
| 535 | base=$(git rev-parse HEAD~4) && |
| 536 | ( |
| 537 | set_fake_editor && |
| 538 | FAKE_COMMIT_AMEND="ONCE" \ |
| 539 | FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \ |
| 540 | EXPECT_HEADER_COUNT=4 \ |
| 541 | git rebase -i $base |
| 542 | ) && |
| 543 | test $base = $(git rev-parse HEAD^) && |
| 544 | git show >output && |
| 545 | grep ONCE output >actual && |
| 546 | test_line_count = 1 actual && |
| 547 | git checkout @{-1} && |
| 548 | git branch -D skip-blank-lines |
| 549 | ' |
| 550 | |
| 551 | test_expect_success 'squash works as expected' ' |
| 552 | git checkout -b squash-works no-conflict-branch && |
| 553 | one=$(git rev-parse HEAD~3) && |
| 554 | ( |
| 555 | set_fake_editor && |
| 556 | FAKE_LINES="1 s 3 2" EXPECT_HEADER_COUNT=2 git rebase -i HEAD~3 |
| 557 | ) && |
| 558 | test $one = $(git rev-parse HEAD~2) |
| 559 | ' |
| 560 | |
| 561 | test_expect_success 'interrupted squash works as expected' ' |
| 562 | git checkout -b interrupted-squash conflict-branch && |
| 563 | one=$(git rev-parse HEAD~3) && |
| 564 | ( |
| 565 | set_fake_editor && |
| 566 | test_must_fail env FAKE_LINES="1 squash 3 2" \ |
| 567 | git rebase -i HEAD~3 |
| 568 | ) && |
| 569 | test_write_lines one two four > conflict && |
| 570 | git add conflict && |
| 571 | test_must_fail git rebase --continue && |
| 572 | echo resolved > conflict && |
| 573 | git add conflict && |
| 574 | git rebase --continue && |
| 575 | test $one = $(git rev-parse HEAD~2) |
| 576 | ' |
| 577 | |
| 578 | test_expect_success 'interrupted squash works as expected (case 2)' ' |
| 579 | git checkout -b interrupted-squash2 conflict-branch && |
| 580 | one=$(git rev-parse HEAD~3) && |
| 581 | ( |
| 582 | set_fake_editor && |
| 583 | test_must_fail env FAKE_LINES="3 squash 1 2" \ |
| 584 | git rebase -i HEAD~3 |
| 585 | ) && |
| 586 | test_write_lines one four > conflict && |
| 587 | git add conflict && |
| 588 | test_must_fail git rebase --continue && |
| 589 | test_write_lines one two four > conflict && |
| 590 | git add conflict && |
| 591 | test_must_fail git rebase --continue && |
| 592 | echo resolved > conflict && |
| 593 | git add conflict && |
| 594 | git rebase --continue && |
| 595 | test $one = $(git rev-parse HEAD~2) |
| 596 | ' |
| 597 | |
| 598 | test_expect_success '--continue tries to commit, even for "edit"' ' |
| 599 | echo unrelated > file7 && |
| 600 | git add file7 && |
| 601 | test_tick && |
| 602 | git commit -m "unrelated change" && |
| 603 | parent=$(git rev-parse HEAD^) && |
| 604 | test_tick && |
| 605 | ( |
| 606 | set_fake_editor && |
| 607 | FAKE_LINES="edit 1" git rebase -i HEAD^ && |
| 608 | echo edited > file7 && |
| 609 | git add file7 && |
| 610 | FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue |
| 611 | ) && |
| 612 | test edited = $(git show HEAD:file7) && |
| 613 | git show HEAD >actual && |
| 614 | test_grep chouette actual && |
| 615 | test $parent = $(git rev-parse HEAD^) |
| 616 | ' |
| 617 | |
| 618 | test_expect_success 'aborted --continue does not squash commits after "edit"' ' |
| 619 | old=$(git rev-parse HEAD) && |
| 620 | test_tick && |
| 621 | ( |
| 622 | set_fake_editor && |
| 623 | FAKE_LINES="edit 1" git rebase -i HEAD^ && |
| 624 | echo "edited again" > file7 && |
| 625 | git add file7 && |
| 626 | test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue |
| 627 | ) && |
| 628 | test $old = $(git rev-parse HEAD) && |
| 629 | git rebase --abort |
| 630 | ' |
| 631 | |
| 632 | test_expect_success 'auto-amend only edited commits after "edit"' ' |
| 633 | test_tick && |
| 634 | ( |
| 635 | set_fake_editor && |
| 636 | FAKE_LINES="edit 1" git rebase -i HEAD^ && |
| 637 | echo "edited again" > file7 && |
| 638 | git add file7 && |
| 639 | FAKE_COMMIT_MESSAGE="edited file7 again" git commit && |
| 640 | echo "and again" > file7 && |
| 641 | git add file7 && |
| 642 | test_tick && |
| 643 | test_must_fail env FAKE_COMMIT_MESSAGE="and again" \ |
| 644 | git rebase --continue |
| 645 | ) && |
| 646 | git rebase --abort |
| 647 | ' |
| 648 | |
| 649 | test_expect_success 'clean error after failed "exec"' ' |
| 650 | test_tick && |
| 651 | test_when_finished "git rebase --abort || :" && |
| 652 | ( |
| 653 | set_fake_editor && |
| 654 | test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ |
| 655 | ) && |
| 656 | echo "edited again" > file7 && |
| 657 | git add file7 && |
| 658 | test_must_fail git rebase --continue 2>error && |
| 659 | test_grep "you have staged changes in your working tree" error && |
| 660 | test_grep ! "could not open.*for reading" error |
| 661 | ' |
| 662 | |
| 663 | test_expect_success 'rebase a detached HEAD' ' |
| 664 | grandparent=$(git rev-parse HEAD~2) && |
| 665 | git checkout $(git rev-parse HEAD) && |
| 666 | test_tick && |
| 667 | ( |
| 668 | set_fake_editor && |
| 669 | FAKE_LINES="2 1" git rebase -i HEAD~2 |
| 670 | ) && |
| 671 | test $grandparent = $(git rev-parse HEAD~2) |
| 672 | ' |
| 673 | |
| 674 | test_expect_success 'rebase a commit violating pre-commit' ' |
| 675 | test_hook pre-commit <<-\EOF && |
| 676 | test -z "$(git diff --cached --check)" |
| 677 | EOF |
| 678 | echo "monde! " >> file1 && |
| 679 | test_tick && |
| 680 | test_must_fail git commit -m doesnt-verify file1 && |
| 681 | git commit -m doesnt-verify --no-verify file1 && |
| 682 | test_tick && |
| 683 | ( |
| 684 | set_fake_editor && |
| 685 | FAKE_LINES=2 git rebase -i HEAD~2 |
| 686 | ) |
| 687 | ' |
| 688 | |
| 689 | test_expect_success 'rebase with a file named HEAD in worktree' ' |
| 690 | git reset --hard && |
| 691 | git checkout -b branch3 A && |
| 692 | |
| 693 | ( |
| 694 | GIT_AUTHOR_NAME="Squashed Away" && |
| 695 | export GIT_AUTHOR_NAME && |
| 696 | >HEAD && |
| 697 | git add HEAD && |
| 698 | git commit -m "Add head" && |
| 699 | >BODY && |
| 700 | git add BODY && |
| 701 | git commit -m "Add body" |
| 702 | ) && |
| 703 | |
| 704 | ( |
| 705 | set_fake_editor && |
| 706 | FAKE_LINES="1 squash 2" git rebase -i @{-1} |
| 707 | ) && |
| 708 | test "$(git show -s --pretty=format:%an)" = "Squashed Away" |
| 709 | |
| 710 | ' |
| 711 | |
| 712 | test_expect_success 'do "noop" when there is nothing to cherry-pick' ' |
| 713 | |
| 714 | git checkout -b branch4 HEAD && |
| 715 | GIT_EDITOR=: git commit --amend \ |
| 716 | --author="Somebody else <somebody@else.com>" && |
| 717 | test $(git rev-parse branch3) != $(git rev-parse branch4) && |
| 718 | git rebase -i branch3 && |
| 719 | test_cmp_rev branch3 branch4 |
| 720 | |
| 721 | ' |
| 722 | |
| 723 | test_expect_success 'submodule rebase setup' ' |
| 724 | git checkout A && |
| 725 | mkdir sub && |
| 726 | ( |
| 727 | cd sub && git init && >elif && |
| 728 | git add elif && git commit -m "submodule initial" |
| 729 | ) && |
| 730 | echo 1 >file1 && |
| 731 | git add file1 sub && |
| 732 | test_tick && |
| 733 | git commit -m "One" && |
| 734 | echo 2 >file1 && |
| 735 | test_tick && |
| 736 | git commit -a -m "Two" && |
| 737 | ( |
| 738 | cd sub && echo 3 >elif && |
| 739 | git commit -a -m "submodule second" |
| 740 | ) && |
| 741 | test_tick && |
| 742 | git commit -a -m "Three changes submodule" |
| 743 | ' |
| 744 | |
| 745 | test_expect_success 'submodule rebase -i' ' |
| 746 | ( |
| 747 | set_fake_editor && |
| 748 | FAKE_LINES="1 squash 2 3" git rebase -i A |
| 749 | ) |
| 750 | ' |
| 751 | |
| 752 | test_expect_success 'submodule conflict setup' ' |
| 753 | git tag submodule-base && |
| 754 | git checkout HEAD^ && |
| 755 | ( |
| 756 | cd sub && git checkout HEAD^ && echo 4 >elif && |
| 757 | git add elif && git commit -m "submodule conflict" |
| 758 | ) && |
| 759 | git add sub && |
| 760 | test_tick && |
| 761 | git commit -m "Conflict in submodule" && |
| 762 | git tag submodule-topic |
| 763 | ' |
| 764 | |
| 765 | test_expect_success 'rebase -i continue with only submodule staged' ' |
| 766 | test_must_fail git rebase -i submodule-base && |
| 767 | git add sub && |
| 768 | git rebase --continue && |
| 769 | test $(git rev-parse submodule-base) != $(git rev-parse HEAD) |
| 770 | ' |
| 771 | |
| 772 | test_expect_success 'rebase -i continue with unstaged submodule' ' |
| 773 | git checkout submodule-topic && |
| 774 | git reset --hard && |
| 775 | test_must_fail git rebase -i submodule-base && |
| 776 | git reset && |
| 777 | git rebase --continue && |
| 778 | test_cmp_rev submodule-base HEAD |
| 779 | ' |
| 780 | |
| 781 | test_expect_success 'avoid unnecessary reset' ' |
| 782 | git checkout primary && |
| 783 | git reset --hard && |
| 784 | test-tool chmtime =123456789 file3 && |
| 785 | git update-index --refresh && |
| 786 | HEAD=$(git rev-parse HEAD) && |
| 787 | git rebase -i HEAD~4 && |
| 788 | test $HEAD = $(git rev-parse HEAD) && |
| 789 | MTIME=$(test-tool chmtime --get file3) && |
| 790 | test 123456789 = $MTIME |
| 791 | ' |
| 792 | |
| 793 | test_expect_success 'reword' ' |
| 794 | git checkout -b reword-branch primary && |
| 795 | ( |
| 796 | set_fake_editor && |
| 797 | FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \ |
| 798 | git rebase -i A && |
| 799 | git show HEAD >actual && |
| 800 | test_grep "E changed" actual && |
| 801 | test $(git rev-parse primary) != $(git rev-parse HEAD) && |
| 802 | test_cmp_rev primary^ HEAD^ && |
| 803 | FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \ |
| 804 | git rebase -i A && |
| 805 | git show HEAD^ >actual && |
| 806 | test_grep "D changed" actual && |
| 807 | FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" \ |
| 808 | git rebase -i A && |
| 809 | git show HEAD~3 >actual && |
| 810 | test_grep "B changed" actual && |
| 811 | FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" \ |
| 812 | git rebase -i A |
| 813 | ) && |
| 814 | git show HEAD~2 >actual && |
| 815 | test_grep "C changed" actual |
| 816 | ' |
| 817 | |
| 818 | test_expect_success 'reword fast-forwarded empty commit' ' |
| 819 | git commit --allow-empty -m "empty commit" --only && |
| 820 | ( |
| 821 | set_fake_editor && |
| 822 | FAKE_COMMIT_AMEND=edited FAKE_LINES="reword 1" \ |
| 823 | git rebase -i HEAD^ |
| 824 | ) && |
| 825 | test_commit_message HEAD <<-\EOF |
| 826 | empty commit |
| 827 | |
| 828 | edited |
| 829 | EOF |
| 830 | ' |
| 831 | |
| 832 | test_expect_success 'no uncommitted changes when rewording and the todo list is reloaded' ' |
| 833 | git checkout E && |
| 834 | test_when_finished "git checkout @{-1}" && |
| 835 | ( |
| 836 | set_fake_editor && |
| 837 | GIT_SEQUENCE_EDITOR="\"$PWD/fake-editor.sh\"" && |
| 838 | export GIT_SEQUENCE_EDITOR && |
| 839 | set_reword_editor && |
| 840 | FAKE_LINES="reword 1 reword 2" git rebase -i C |
| 841 | ) && |
| 842 | check_reworded_commits D E |
| 843 | ' |
| 844 | |
| 845 | test_expect_success 'rebase -i can copy notes' ' |
| 846 | git config notes.rewrite.rebase true && |
| 847 | git config notes.rewriteRef "refs/notes/*" && |
| 848 | test_commit n1 && |
| 849 | test_commit n2 && |
| 850 | test_commit n3 && |
| 851 | git notes add -m"a note" n3 && |
| 852 | git rebase -i --onto n1 n2 && |
| 853 | test "a note" = "$(git notes show HEAD)" |
| 854 | ' |
| 855 | |
| 856 | test_expect_success 'rebase -i can copy notes over a fixup' ' |
| 857 | cat >expect <<-\EOF && |
| 858 | an earlier note |
| 859 | |
| 860 | a note |
| 861 | EOF |
| 862 | git reset --hard n3 && |
| 863 | git notes add -m"an earlier note" n2 && |
| 864 | ( |
| 865 | set_fake_editor && |
| 866 | GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 f 2" \ |
| 867 | git rebase -i n1 |
| 868 | ) && |
| 869 | git notes show > output && |
| 870 | test_cmp expect output |
| 871 | ' |
| 872 | |
| 873 | test_expect_success 'rebase while detaching HEAD' ' |
| 874 | git symbolic-ref HEAD && |
| 875 | grandparent=$(git rev-parse HEAD~2) && |
| 876 | test_tick && |
| 877 | ( |
| 878 | set_fake_editor && |
| 879 | FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 |
| 880 | ) && |
| 881 | test $grandparent = $(git rev-parse HEAD~2) && |
| 882 | test_must_fail git symbolic-ref HEAD |
| 883 | ' |
| 884 | |
| 885 | test_tick # Ensure that the rebased commits get a different timestamp. |
| 886 | test_expect_success 'always cherry-pick with --no-ff' ' |
| 887 | git checkout no-ff-branch && |
| 888 | git tag original-no-ff-branch && |
| 889 | git rebase -i --no-ff A && |
| 890 | for p in 0 1 2 |
| 891 | do |
| 892 | test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) && |
| 893 | git diff HEAD~$p original-no-ff-branch~$p > out && |
| 894 | test_must_be_empty out || return 1 |
| 895 | done && |
| 896 | test_cmp_rev HEAD~3 original-no-ff-branch~3 && |
| 897 | git diff HEAD~3 original-no-ff-branch~3 > out && |
| 898 | test_must_be_empty out |
| 899 | ' |
| 900 | |
| 901 | test_expect_success 'set up commits with funny messages' ' |
| 902 | git checkout -b funny A && |
| 903 | echo >>file1 && |
| 904 | test_tick && |
| 905 | git commit -a -m "end with slash\\" && |
| 906 | echo >>file1 && |
| 907 | test_tick && |
| 908 | git commit -a -m "something (\000) that looks like octal" && |
| 909 | echo >>file1 && |
| 910 | test_tick && |
| 911 | git commit -a -m "something (\n) that looks like a newline" && |
| 912 | echo >>file1 && |
| 913 | test_tick && |
| 914 | git commit -a -m "another commit" |
| 915 | ' |
| 916 | |
| 917 | test_expect_success 'rebase-i history with funny messages' ' |
| 918 | git rev-list A..funny >expect && |
| 919 | test_tick && |
| 920 | ( |
| 921 | set_fake_editor && |
| 922 | FAKE_LINES="1 2 3 4" git rebase -i A |
| 923 | ) && |
| 924 | git rev-list A.. >actual && |
| 925 | test_cmp expect actual |
| 926 | ' |
| 927 | |
| 928 | test_expect_success 'prepare for rebase -i --exec' ' |
| 929 | git checkout primary && |
| 930 | git checkout -b execute && |
| 931 | test_commit one_exec main.txt one_exec && |
| 932 | test_commit two_exec main.txt two_exec && |
| 933 | test_commit three_exec main.txt three_exec |
| 934 | ' |
| 935 | |
| 936 | test_expect_success 'running "git rebase -i --exec git show HEAD"' ' |
| 937 | ( |
| 938 | set_fake_editor && |
| 939 | git rebase -i --exec "git show HEAD" HEAD~2 >actual && |
| 940 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && |
| 941 | export FAKE_LINES && |
| 942 | git rebase -i HEAD~2 >expect |
| 943 | ) && |
| 944 | sed -e "1,9d" expect >expected && |
| 945 | test_cmp expected actual |
| 946 | ' |
| 947 | |
| 948 | test_expect_success 'running "git rebase --exec git show HEAD -i"' ' |
| 949 | git reset --hard execute && |
| 950 | ( |
| 951 | set_fake_editor && |
| 952 | git rebase --exec "git show HEAD" -i HEAD~2 >actual && |
| 953 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && |
| 954 | export FAKE_LINES && |
| 955 | git rebase -i HEAD~2 >expect |
| 956 | ) && |
| 957 | sed -e "1,9d" expect >expected && |
| 958 | test_cmp expected actual |
| 959 | ' |
| 960 | |
| 961 | test_expect_success 'running "git rebase -ix git show HEAD"' ' |
| 962 | git reset --hard execute && |
| 963 | ( |
| 964 | set_fake_editor && |
| 965 | git rebase -ix "git show HEAD" HEAD~2 >actual && |
| 966 | FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && |
| 967 | export FAKE_LINES && |
| 968 | git rebase -i HEAD~2 >expect |
| 969 | ) && |
| 970 | sed -e "1,9d" expect >expected && |
| 971 | test_cmp expected actual |
| 972 | ' |
| 973 | |
| 974 | |
| 975 | test_expect_success 'rebase -ix with several <CMD>' ' |
| 976 | git reset --hard execute && |
| 977 | ( |
| 978 | set_fake_editor && |
| 979 | git rebase -ix "git show HEAD; pwd" HEAD~2 >actual && |
| 980 | FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" && |
| 981 | export FAKE_LINES && |
| 982 | git rebase -i HEAD~2 >expect |
| 983 | ) && |
| 984 | sed -e "1,9d" expect >expected && |
| 985 | test_cmp expected actual |
| 986 | ' |
| 987 | |
| 988 | test_expect_success 'rebase -ix with several instances of --exec' ' |
| 989 | git reset --hard execute && |
| 990 | ( |
| 991 | set_fake_editor && |
| 992 | git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual && |
| 993 | FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2 |
| 994 | exec_git_show_HEAD exec_pwd" && |
| 995 | export FAKE_LINES && |
| 996 | git rebase -i HEAD~2 >expect |
| 997 | ) && |
| 998 | sed -e "1,11d" expect >expected && |
| 999 | test_cmp expected actual |
| 1000 | ' |
| 1001 | |
| 1002 | test_expect_success 'rebase -ix with --autosquash' ' |
| 1003 | git reset --hard execute && |
| 1004 | git checkout -b autosquash && |
| 1005 | echo second >second.txt && |
| 1006 | git add second.txt && |
| 1007 | git commit -m "fixup! two_exec" && |
| 1008 | echo bis >bis.txt && |
| 1009 | git add bis.txt && |
| 1010 | git commit -m "fixup! two_exec" && |
| 1011 | git checkout -b autosquash_actual && |
| 1012 | git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual && |
| 1013 | git checkout autosquash && |
| 1014 | ( |
| 1015 | set_fake_editor && |
| 1016 | git checkout -b autosquash_expected && |
| 1017 | FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" && |
| 1018 | export FAKE_LINES && |
| 1019 | git rebase -i HEAD~4 >expect |
| 1020 | ) && |
| 1021 | sed -e "1,13d" expect >expected && |
| 1022 | test_cmp expected actual |
| 1023 | ' |
| 1024 | |
| 1025 | test_expect_success 'rebase --exec works without -i ' ' |
| 1026 | git reset --hard execute && |
| 1027 | rm -rf exec_output && |
| 1028 | EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual && |
| 1029 | test_grep "Successfully rebased and updated" actual && |
| 1030 | test_line_count = 2 exec_output && |
| 1031 | test_path_is_missing invoked_editor |
| 1032 | ' |
| 1033 | |
| 1034 | test_expect_success 'rebase -i --exec without <CMD>' ' |
| 1035 | git reset --hard execute && |
| 1036 | test_must_fail git rebase -i --exec 2>actual && |
| 1037 | test_grep "requires a value" actual && |
| 1038 | git checkout primary |
| 1039 | ' |
| 1040 | |
| 1041 | test_expect_success 'rebase -i --root re-order and drop commits' ' |
| 1042 | git checkout E && |
| 1043 | ( |
| 1044 | set_fake_editor && |
| 1045 | FAKE_LINES="3 1 2 5" git rebase -i --root |
| 1046 | ) && |
| 1047 | test E = $(git cat-file commit HEAD | sed -ne \$p) && |
| 1048 | test B = $(git cat-file commit HEAD^ | sed -ne \$p) && |
| 1049 | test A = $(git cat-file commit HEAD^^ | sed -ne \$p) && |
| 1050 | test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) && |
| 1051 | test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ ) |
| 1052 | ' |
| 1053 | |
| 1054 | test_expect_success 'rebase -i --root retain root commit author and message' ' |
| 1055 | git checkout A && |
| 1056 | echo B >file7 && |
| 1057 | git add file7 && |
| 1058 | GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && |
| 1059 | ( |
| 1060 | set_fake_editor && |
| 1061 | FAKE_LINES="2" git rebase -i --root |
| 1062 | ) && |
| 1063 | git cat-file commit HEAD >output && |
| 1064 | test_grep -q "^author Twerp Snog" output && |
| 1065 | git cat-file commit HEAD >actual && |
| 1066 | test_grep -q "^different author$" actual |
| 1067 | ' |
| 1068 | |
| 1069 | test_expect_success 'rebase -i --root temporary sentinel commit' ' |
| 1070 | git checkout B && |
| 1071 | ( |
| 1072 | set_fake_editor && |
| 1073 | test_must_fail env FAKE_LINES="2" git rebase -i --root |
| 1074 | ) && |
| 1075 | git cat-file commit HEAD >actual && |
| 1076 | test_grep "^tree $EMPTY_TREE" actual && |
| 1077 | git rebase --abort |
| 1078 | ' |
| 1079 | |
| 1080 | test_expect_success 'rebase -i --root fixup root commit' ' |
| 1081 | git checkout B && |
| 1082 | ( |
| 1083 | set_fake_editor && |
| 1084 | FAKE_LINES="1 fixup 2" git rebase -i --root |
| 1085 | ) && |
| 1086 | test A = $(git cat-file commit HEAD | sed -ne \$p) && |
| 1087 | test B = $(git show HEAD:file1) && |
| 1088 | test 0 = $(git cat-file commit HEAD | grep -c ^parent\ ) |
| 1089 | ' |
| 1090 | |
| 1091 | test_expect_success 'rebase -i --root reword original root commit' ' |
| 1092 | test_when_finished "test_might_fail git rebase --abort" && |
| 1093 | git checkout -b reword-original-root-branch primary && |
| 1094 | ( |
| 1095 | set_fake_editor && |
| 1096 | FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \ |
| 1097 | git rebase -i --root |
| 1098 | ) && |
| 1099 | git show HEAD^ >actual && |
| 1100 | test_grep "A changed" actual && |
| 1101 | test -z "$(git show -s --format=%p HEAD^)" |
| 1102 | ' |
| 1103 | |
| 1104 | test_expect_success 'rebase -i --root reword new root commit' ' |
| 1105 | test_when_finished "test_might_fail git rebase --abort" && |
| 1106 | git checkout -b reword-now-root-branch primary && |
| 1107 | ( |
| 1108 | set_fake_editor && |
| 1109 | FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \ |
| 1110 | git rebase -i --root |
| 1111 | ) && |
| 1112 | git show HEAD^ >actual && |
| 1113 | test_grep "C changed" actual && |
| 1114 | test -z "$(git show -s --format=%p HEAD^)" |
| 1115 | ' |
| 1116 | |
| 1117 | test_expect_success 'rebase -i --root when root has untracked file conflict' ' |
| 1118 | test_when_finished "reset_rebase" && |
| 1119 | git checkout -b failing-root-pick A && |
| 1120 | echo x >file2 && |
| 1121 | git rm file1 && |
| 1122 | git commit -m "remove file 1 add file 2" && |
| 1123 | echo z >file1 && |
| 1124 | ( |
| 1125 | set_fake_editor && |
| 1126 | test_must_fail env FAKE_LINES="1 2" git rebase -i --root |
| 1127 | ) && |
| 1128 | rm file1 && |
| 1129 | git rebase --continue && |
| 1130 | test "$(git log -1 --format=%B)" = "remove file 1 add file 2" && |
| 1131 | test "$(git rev-list --count HEAD)" = 2 |
| 1132 | ' |
| 1133 | |
| 1134 | test_expect_success 'rebase -i --root reword root when root has untracked file conflict' ' |
| 1135 | test_when_finished "reset_rebase" && |
| 1136 | echo z>file1 && |
| 1137 | ( |
| 1138 | set_fake_editor && |
| 1139 | test_must_fail env FAKE_LINES="reword 1 2" \ |
| 1140 | FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root && |
| 1141 | rm file1 && |
| 1142 | FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue |
| 1143 | ) && |
| 1144 | test "$(git log -1 --format=%B HEAD^)" = "Reworded A" && |
| 1145 | test "$(git rev-list --count HEAD)" = 2 |
| 1146 | ' |
| 1147 | |
| 1148 | test_expect_success 'rebase --edit-todo does not work on non-interactive rebase' ' |
| 1149 | git checkout reword-original-root-branch && |
| 1150 | git reset --hard && |
| 1151 | git checkout conflict-branch && |
| 1152 | ( |
| 1153 | set_fake_editor && |
| 1154 | test_must_fail git rebase -f --apply --onto HEAD~2 HEAD~ && |
| 1155 | test_must_fail git rebase --edit-todo |
| 1156 | ) && |
| 1157 | git rebase --abort |
| 1158 | ' |
| 1159 | |
| 1160 | test_expect_success 'rebase --edit-todo can be used to modify todo' ' |
| 1161 | git reset --hard && |
| 1162 | git checkout no-conflict-branch^0 && |
| 1163 | ( |
| 1164 | set_fake_editor && |
| 1165 | FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 && |
| 1166 | FAKE_LINES="2 1" git rebase --edit-todo && |
| 1167 | git rebase --continue |
| 1168 | ) && |
| 1169 | test M = $(git cat-file commit HEAD^ | sed -ne \$p) && |
| 1170 | test L = $(git cat-file commit HEAD | sed -ne \$p) |
| 1171 | ' |
| 1172 | |
| 1173 | test_expect_success 'rebase -i produces readable reflog' ' |
| 1174 | git reset --hard && |
| 1175 | git branch -f branch-reflog-test H && |
| 1176 | git rebase -i --onto I F branch-reflog-test && |
| 1177 | cat >expect <<-\EOF && |
| 1178 | rebase (finish): returning to refs/heads/branch-reflog-test |
| 1179 | rebase (pick): H |
| 1180 | rebase (pick): G |
| 1181 | rebase (start): checkout I |
| 1182 | EOF |
| 1183 | git reflog -n4 HEAD | |
| 1184 | sed "s/[^:]*: //" >actual && |
| 1185 | test_cmp expect actual |
| 1186 | ' |
| 1187 | |
| 1188 | test_expect_success 'rebase -i respects core.commentchar' ' |
| 1189 | git reset --hard && |
| 1190 | git checkout E^0 && |
| 1191 | test_config core.commentchar "\\" && |
| 1192 | write_script remove-all-but-first.sh <<-\EOF && |
| 1193 | sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" && |
| 1194 | mv "$1.tmp" "$1" |
| 1195 | EOF |
| 1196 | ( |
| 1197 | test_set_editor "$(pwd)/remove-all-but-first.sh" && |
| 1198 | git rebase -i B |
| 1199 | ) && |
| 1200 | test B = $(git cat-file commit HEAD^ | sed -ne \$p) |
| 1201 | ' |
| 1202 | |
| 1203 | test_expect_success !WITH_BREAKING_CHANGES 'rebase -i respects core.commentchar=auto' ' |
| 1204 | test_config core.commentchar auto && |
| 1205 | write_script copy-edit-script.sh <<-\EOF && |
| 1206 | cp "$1" edit-script |
| 1207 | EOF |
| 1208 | test_when_finished "git rebase --abort || :" && |
| 1209 | ( |
| 1210 | test_set_editor "$(pwd)/copy-edit-script.sh" && |
| 1211 | git rebase -i HEAD^ 2>err |
| 1212 | ) && |
| 1213 | sed -n "s/^hint: *\$//p; s/^hint: //p; s/^warning: //p" err >actual && |
| 1214 | cat >expect <<-EOF && |
| 1215 | Support for ${SQ}core.commentChar=auto${SQ} is deprecated and will be removed in Git 3.0 |
| 1216 | |
| 1217 | To use the default comment string (#) please run |
| 1218 | |
| 1219 | git config unset core.commentChar |
| 1220 | |
| 1221 | To set a custom comment string please run |
| 1222 | |
| 1223 | git config set core.commentChar <comment string> |
| 1224 | |
| 1225 | where ${SQ}<comment string>${SQ} is the string you wish to use. |
| 1226 | EOF |
| 1227 | test_cmp expect actual && |
| 1228 | test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)" |
| 1229 | ' |
| 1230 | |
| 1231 | test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' ' |
| 1232 | test_when_finished "git branch -D torebase" && |
| 1233 | git checkout -b torebase branch1 && |
| 1234 | upstream=$(git rev-parse ":/J") && |
| 1235 | onto=$(git rev-parse ":/A") && |
| 1236 | git rebase --onto $onto $upstream && |
| 1237 | git reset --hard branch1 && |
| 1238 | git rebase --onto ":/A" ":/J" && |
| 1239 | git checkout branch1 |
| 1240 | ' |
| 1241 | |
| 1242 | test_expect_success 'rebase -i with --strategy and -X' ' |
| 1243 | git checkout -b conflict-merge-use-theirs conflict-branch && |
| 1244 | git reset --hard HEAD^ && |
| 1245 | echo five >conflict && |
| 1246 | echo Z >file1 && |
| 1247 | git commit -a -m "one file conflict" && |
| 1248 | EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch && |
| 1249 | test $(git show conflict-branch:conflict) = $(cat conflict) && |
| 1250 | test $(cat file1) = Z |
| 1251 | ' |
| 1252 | |
| 1253 | test_expect_success 'interrupted rebase -i with --strategy and -X' ' |
| 1254 | git checkout -b conflict-merge-use-theirs-interrupted conflict-branch && |
| 1255 | git reset --hard HEAD^ && |
| 1256 | >breakpoint && |
| 1257 | git add breakpoint && |
| 1258 | git commit -m "breakpoint for interactive mode" && |
| 1259 | echo five >conflict && |
| 1260 | echo Z >file1 && |
| 1261 | git commit -a -m "one file conflict" && |
| 1262 | ( |
| 1263 | set_fake_editor && |
| 1264 | FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive \ |
| 1265 | -Xours conflict-branch |
| 1266 | ) && |
| 1267 | git rebase --continue && |
| 1268 | test $(git show conflict-branch:conflict) = $(cat conflict) && |
| 1269 | test $(cat file1) = Z |
| 1270 | ' |
| 1271 | |
| 1272 | test_expect_success 'failing pick with --strategy is rescheduled' ' |
| 1273 | test_when_finished "rm -rf bin; test_might_fail git rebase --abort" && |
| 1274 | mkdir bin && |
| 1275 | echo exit 2 | write_script bin/git-merge-fail && |
| 1276 | git log -1 --format="pick %H # %s" HEAD >expect && |
| 1277 | test_must_fail env PATH="$PWD/bin:$PATH" \ |
| 1278 | git rebase --no-ff --strategy fail HEAD^ && |
| 1279 | test_cmp expect .git/rebase-merge/git-rebase-todo && |
| 1280 | test_cmp expect .git/rebase-merge/done |
| 1281 | ' |
| 1282 | |
| 1283 | test_expect_success 'rebase -i error on commits with \ in message' ' |
| 1284 | current_head=$(git rev-parse HEAD) && |
| 1285 | test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" && |
| 1286 | test_commit TO-REMOVE will-conflict old-content && |
| 1287 | test_commit "\temp" will-conflict new-content dummy && |
| 1288 | test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error && |
| 1289 | test_expect_code 1 grep " emp" error |
| 1290 | ' |
| 1291 | |
| 1292 | test_expect_success 'short commit ID setup' ' |
| 1293 | test_when_finished "git checkout primary" && |
| 1294 | git checkout --orphan collide && |
| 1295 | git rm -rf . && |
| 1296 | ( |
| 1297 | unset test_tick && |
| 1298 | test_commit collide1 collide && |
| 1299 | test_commit --notick collide2 collide && |
| 1300 | test_commit --notick collide3 collide |
| 1301 | ) |
| 1302 | ' |
| 1303 | |
| 1304 | if test -n "$GIT_TEST_FIND_COLLIDER" |
| 1305 | then |
| 1306 | author="$(unset test_tick; test_tick; git var GIT_AUTHOR_IDENT)" |
| 1307 | committer="$(unset test_tick; test_tick; git var GIT_COMMITTER_IDENT)" |
| 1308 | blob="$(git rev-parse collide2:collide)" |
| 1309 | from="$(git rev-parse collide1^0)" |
| 1310 | repl="commit refs/heads/collider-&\\n" |
| 1311 | repl="${repl}author $author\\ncommitter $committer\\n" |
| 1312 | repl="${repl}data <<EOF\\ncollide2 &\\nEOF\\n" |
| 1313 | repl="${repl}from $from\\nM 100644 $blob collide\\n" |
| 1314 | test_seq 1 32768 | sed "s|.*|$repl|" >script && |
| 1315 | git fast-import <script && |
| 1316 | git pack-refs && |
| 1317 | git for-each-ref >refs && |
| 1318 | grep "^$(test_oid t3404_collision)" <refs >matches && |
| 1319 | cat matches && |
| 1320 | test_line_count -gt 2 matches || { |
| 1321 | echo "Could not find a collider" >&2 |
| 1322 | exit 1 |
| 1323 | } |
| 1324 | fi |
| 1325 | |
| 1326 | test_expect_success 'short commit ID collide' ' |
| 1327 | test_oid_cache <<-EOF && |
| 1328 | # collision-related constants |
| 1329 | t3404_collision sha1:6bcd |
| 1330 | t3404_collision sha256:0161 |
| 1331 | t3404_collider sha1:ac4f2ee |
| 1332 | t3404_collider sha256:16697 |
| 1333 | EOF |
| 1334 | test_when_finished "reset_rebase && git checkout primary" && |
| 1335 | git checkout collide && |
| 1336 | colliding_id=$(test_oid t3404_collision) && |
| 1337 | hexsz=$(test_oid hexsz) && |
| 1338 | test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" && |
| 1339 | test_config core.abbrev 4 && |
| 1340 | ( |
| 1341 | unset test_tick && |
| 1342 | test_tick && |
| 1343 | set_fake_editor && |
| 1344 | FAKE_COMMIT_MESSAGE="collide2 $(test_oid t3404_collider)" \ |
| 1345 | FAKE_LINES="reword 1 break 2" git rebase -i HEAD~2 && |
| 1346 | test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" && |
| 1347 | test_grep "^pick $colliding_id " \ |
| 1348 | .git/rebase-merge/git-rebase-todo.tmp && |
| 1349 | test_grep -E "^pick [0-9a-f]{$hexsz}" \ |
| 1350 | .git/rebase-merge/git-rebase-todo && |
| 1351 | test_grep -E "^pick [0-9a-f]{$hexsz}" \ |
| 1352 | .git/rebase-merge/git-rebase-todo.backup && |
| 1353 | git rebase --continue |
| 1354 | ) && |
| 1355 | collide2="$(git rev-parse HEAD~1 | cut -c 1-4)" && |
| 1356 | collide3="$(git rev-parse collide3 | cut -c 1-4)" && |
| 1357 | test "$collide2" = "$collide3" |
| 1358 | ' |
| 1359 | |
| 1360 | test_expect_success 'respect core.abbrev' ' |
| 1361 | git config core.abbrev 12 && |
| 1362 | ( |
| 1363 | set_cat_todo_editor && |
| 1364 | test_must_fail git rebase -i HEAD~4 >todo-list |
| 1365 | ) && |
| 1366 | test 4 = $(grep -c -E "pick [0-9a-f]{12,}" todo-list) |
| 1367 | ' |
| 1368 | |
| 1369 | test_expect_success 'todo count' ' |
| 1370 | write_script dump-raw.sh <<-\EOF && |
| 1371 | cat "$1" |
| 1372 | EOF |
| 1373 | ( |
| 1374 | test_set_editor "$(pwd)/dump-raw.sh" && |
| 1375 | git rebase -i HEAD~4 >actual |
| 1376 | ) && |
| 1377 | test_grep "^# Rebase ..* onto ..* ([0-9]" actual |
| 1378 | ' |
| 1379 | |
| 1380 | test_expect_success 'rebase -i commits that overwrite untracked files (pick)' ' |
| 1381 | git checkout --force A && |
| 1382 | git clean -f && |
| 1383 | cat >todo <<-EOF && |
| 1384 | exec >file2 |
| 1385 | pick $(git rev-parse B) B |
| 1386 | pick $(git rev-parse C) C |
| 1387 | pick $(git rev-parse D) D |
| 1388 | exec cat .git/rebase-merge/done >actual |
| 1389 | EOF |
| 1390 | ( |
| 1391 | set_replace_editor todo && |
| 1392 | test_must_fail git rebase -i A |
| 1393 | ) && |
| 1394 | test_cmp_rev HEAD B && |
| 1395 | test_cmp_rev REBASE_HEAD C && |
| 1396 | head -n3 todo >expect && |
| 1397 | test_cmp expect .git/rebase-merge/done && |
| 1398 | rm file2 && |
| 1399 | test_path_is_missing .git/rebase-merge/patch && |
| 1400 | echo changed >file1 && |
| 1401 | git add file1 && |
| 1402 | test_must_fail git rebase --continue 2>err && |
| 1403 | test_grep "error: you have staged changes in your working tree" err && |
| 1404 | git reset --hard HEAD && |
| 1405 | git rebase --continue && |
| 1406 | test_cmp_rev HEAD D && |
| 1407 | tail -n3 todo >>expect && |
| 1408 | test_cmp expect actual |
| 1409 | ' |
| 1410 | |
| 1411 | test_expect_success 'rebase -i commits that overwrite untracked files (squash)' ' |
| 1412 | git checkout --force branch2 && |
| 1413 | git clean -f && |
| 1414 | git tag original-branch2 && |
| 1415 | ( |
| 1416 | set_fake_editor && |
| 1417 | FAKE_LINES="edit 1 squash 2" git rebase -i A |
| 1418 | ) && |
| 1419 | test_cmp_rev HEAD F && |
| 1420 | test_path_is_missing file6 && |
| 1421 | >file6 && |
| 1422 | test_must_fail git rebase --continue && |
| 1423 | test_cmp_rev HEAD F && |
| 1424 | test_cmp_rev REBASE_HEAD I && |
| 1425 | rm file6 && |
| 1426 | test_path_is_missing .git/rebase-merge/patch && |
| 1427 | echo changed >file1 && |
| 1428 | git add file1 && |
| 1429 | test_must_fail git rebase --continue 2>err && |
| 1430 | test_grep "error: you have staged changes in your working tree" err && |
| 1431 | git reset --hard HEAD && |
| 1432 | git rebase --continue && |
| 1433 | test $(git cat-file commit HEAD | sed -ne \$p) = I && |
| 1434 | git reset --hard original-branch2 |
| 1435 | ' |
| 1436 | |
| 1437 | test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' ' |
| 1438 | git checkout --force branch2 && |
| 1439 | git clean -f && |
| 1440 | ( |
| 1441 | set_fake_editor && |
| 1442 | FAKE_LINES="edit 1 2" git rebase -i --no-ff A |
| 1443 | ) && |
| 1444 | test $(git cat-file commit HEAD | sed -ne \$p) = F && |
| 1445 | test_path_is_missing file6 && |
| 1446 | >file6 && |
| 1447 | test_must_fail git rebase --continue && |
| 1448 | test $(git cat-file commit HEAD | sed -ne \$p) = F && |
| 1449 | test_cmp_rev REBASE_HEAD I && |
| 1450 | rm file6 && |
| 1451 | test_path_is_missing .git/rebase-merge/patch && |
| 1452 | echo changed >file1 && |
| 1453 | git add file1 && |
| 1454 | test_must_fail git rebase --continue 2>err && |
| 1455 | test_grep "error: you have staged changes in your working tree" err && |
| 1456 | git reset --hard HEAD && |
| 1457 | git rebase --continue && |
| 1458 | test $(git cat-file commit HEAD | sed -ne \$p) = I |
| 1459 | ' |
| 1460 | |
| 1461 | test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' ' |
| 1462 | git checkout -b commit-to-skip && |
| 1463 | for double in X 3 1 |
| 1464 | do |
| 1465 | test_seq 5 | sed "s/$double/&&/" >seq && |
| 1466 | git add seq && |
| 1467 | test_tick && |
| 1468 | git commit -m seq-$double || return 1 |
| 1469 | done && |
| 1470 | git tag seq-onto && |
| 1471 | git reset --hard HEAD~2 && |
| 1472 | git cherry-pick seq-onto && |
| 1473 | ( |
| 1474 | set_fake_editor && |
| 1475 | test_must_fail env FAKE_LINES= git rebase -i seq-onto |
| 1476 | ) && |
| 1477 | test -d .git/rebase-merge && |
| 1478 | git rebase --continue && |
| 1479 | git diff --exit-code seq-onto && |
| 1480 | test ! -d .git/rebase-merge && |
| 1481 | test ! -f .git/CHERRY_PICK_HEAD |
| 1482 | ' |
| 1483 | |
| 1484 | rebase_setup_and_clean () { |
| 1485 | test_when_finished " |
| 1486 | git checkout primary && |
| 1487 | test_might_fail git branch -D $1 && |
| 1488 | test_might_fail git rebase --abort |
| 1489 | " && |
| 1490 | git checkout -b $1 ${2:-primary} |
| 1491 | } |
| 1492 | |
| 1493 | test_expect_success 'drop' ' |
| 1494 | rebase_setup_and_clean drop-test && |
| 1495 | ( |
| 1496 | set_fake_editor && |
| 1497 | FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root |
| 1498 | ) && |
| 1499 | test E = $(git cat-file commit HEAD | sed -ne \$p) && |
| 1500 | test C = $(git cat-file commit HEAD^ | sed -ne \$p) && |
| 1501 | test A = $(git cat-file commit HEAD^^ | sed -ne \$p) |
| 1502 | ' |
| 1503 | |
| 1504 | test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' ' |
| 1505 | test_config rebase.missingCommitsCheck ignore && |
| 1506 | rebase_setup_and_clean missing-commit && |
| 1507 | ( |
| 1508 | set_fake_editor && |
| 1509 | FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual |
| 1510 | ) && |
| 1511 | test D = $(git cat-file commit HEAD | sed -ne \$p) && |
| 1512 | test_grep \ |
| 1513 | "Successfully rebased and updated refs/heads/missing-commit" \ |
| 1514 | actual |
| 1515 | ' |
| 1516 | |
| 1517 | test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' ' |
| 1518 | cat >expect <<-EOF && |
| 1519 | Warning: some commits may have been dropped accidentally. |
| 1520 | Dropped commits (newer to older): |
| 1521 | - $(git log --format="%h # %s" -1 primary) |
| 1522 | To avoid this message, use "drop" to explicitly remove a commit. |
| 1523 | EOF |
| 1524 | test_config rebase.missingCommitsCheck warn && |
| 1525 | rebase_setup_and_clean missing-commit && |
| 1526 | ( |
| 1527 | set_fake_editor && |
| 1528 | FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual.2 |
| 1529 | ) && |
| 1530 | head -n4 actual.2 >actual && |
| 1531 | test_cmp expect actual && |
| 1532 | test D = $(git cat-file commit HEAD | sed -ne \$p) |
| 1533 | ' |
| 1534 | |
| 1535 | test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' |
| 1536 | cat >expect <<-EOF && |
| 1537 | Warning: some commits may have been dropped accidentally. |
| 1538 | Dropped commits (newer to older): |
| 1539 | - $(git log --format="%h # %s" -1 primary) |
| 1540 | - $(git log --format="%h # %s" -1 primary~2) |
| 1541 | To avoid this message, use "drop" to explicitly remove a commit. |
| 1542 | |
| 1543 | Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings. |
| 1544 | The possible behaviours are: ignore, warn, error. |
| 1545 | |
| 1546 | You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''. |
| 1547 | Or you can abort the rebase with '\''git rebase --abort'\''. |
| 1548 | EOF |
| 1549 | test_config rebase.missingCommitsCheck error && |
| 1550 | rebase_setup_and_clean missing-commit && |
| 1551 | ( |
| 1552 | set_fake_editor && |
| 1553 | test_must_fail env FAKE_LINES="1 2 4" \ |
| 1554 | git rebase -i --root 2>actual && |
| 1555 | test_cmp expect actual && |
| 1556 | cp .git/rebase-merge/git-rebase-todo.backup \ |
| 1557 | .git/rebase-merge/git-rebase-todo && |
| 1558 | FAKE_LINES="1 2 drop 3 4 drop 5" git rebase --edit-todo |
| 1559 | ) && |
| 1560 | git rebase --continue && |
| 1561 | test D = $(git cat-file commit HEAD | sed -ne \$p) && |
| 1562 | test B = $(git cat-file commit HEAD^ | sed -ne \$p) |
| 1563 | ' |
| 1564 | |
| 1565 | test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ignore' ' |
| 1566 | test_config rebase.missingCommitsCheck ignore && |
| 1567 | rebase_setup_and_clean missing-commit && |
| 1568 | ( |
| 1569 | set_fake_editor && |
| 1570 | FAKE_LINES="break 1 2 3 4 5" git rebase -i --root && |
| 1571 | FAKE_LINES="1 2 3 4" git rebase --edit-todo && |
| 1572 | git rebase --continue 2>actual |
| 1573 | ) && |
| 1574 | test D = $(git cat-file commit HEAD | sed -ne \$p) && |
| 1575 | test_grep \ |
| 1576 | "Successfully rebased and updated refs/heads/missing-commit" \ |
| 1577 | actual |
| 1578 | ' |
| 1579 | |
| 1580 | test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' ' |
| 1581 | cat >expect <<-EOF && |
| 1582 | error: invalid command '\''pickled'\'' |
| 1583 | error: invalid line 1: pickled $(git log --format="%h # %s" -1 primary~4) |
| 1584 | Warning: some commits may have been dropped accidentally. |
| 1585 | Dropped commits (newer to older): |
| 1586 | - $(git log --format="%h # %s" -1 primary) |
| 1587 | - $(git log --format="%h # %s" -1 primary~4) |
| 1588 | To avoid this message, use "drop" to explicitly remove a commit. |
| 1589 | EOF |
| 1590 | head -n5 expect >expect.2 && |
| 1591 | tail -n1 expect >>expect.2 && |
| 1592 | tail -n4 expect.2 >expect.3 && |
| 1593 | test_config rebase.missingCommitsCheck warn && |
| 1594 | rebase_setup_and_clean missing-commit && |
| 1595 | ( |
| 1596 | set_fake_editor && |
| 1597 | test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \ |
| 1598 | git rebase -i --root && |
| 1599 | cp .git/rebase-merge/git-rebase-todo.backup orig && |
| 1600 | FAKE_LINES="2 3 4" git rebase --edit-todo 2>actual.2 && |
| 1601 | head -n7 actual.2 >actual && |
| 1602 | test_cmp expect actual && |
| 1603 | cp orig .git/rebase-merge/git-rebase-todo && |
| 1604 | FAKE_LINES="1 2 3 4" git rebase --edit-todo 2>actual.2 && |
| 1605 | head -n4 actual.2 >actual && |
| 1606 | test_cmp expect.3 actual && |
| 1607 | git rebase --continue 2>actual |
| 1608 | ) && |
| 1609 | test D = $(git cat-file commit HEAD | sed -ne \$p) && |
| 1610 | test_grep \ |
| 1611 | "Successfully rebased and updated refs/heads/missing-commit" \ |
| 1612 | actual |
| 1613 | ' |
| 1614 | |
| 1615 | test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' ' |
| 1616 | cat >expect <<-EOF && |
| 1617 | error: invalid command '\''pickled'\'' |
| 1618 | error: invalid line 1: pickled $(git log --format="%h # %s" -1 primary~4) |
| 1619 | Warning: some commits may have been dropped accidentally. |
| 1620 | Dropped commits (newer to older): |
| 1621 | - $(git log --format="%h # %s" -1 primary) |
| 1622 | - $(git log --format="%h # %s" -1 primary~4) |
| 1623 | To avoid this message, use "drop" to explicitly remove a commit. |
| 1624 | |
| 1625 | Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings. |
| 1626 | The possible behaviours are: ignore, warn, error. |
| 1627 | |
| 1628 | You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''. |
| 1629 | Or you can abort the rebase with '\''git rebase --abort'\''. |
| 1630 | EOF |
| 1631 | tail -n11 expect >expect.2 && |
| 1632 | head -n3 expect.2 >expect.3 && |
| 1633 | tail -n7 expect.2 >>expect.3 && |
| 1634 | test_config rebase.missingCommitsCheck error && |
| 1635 | rebase_setup_and_clean missing-commit && |
| 1636 | ( |
| 1637 | set_fake_editor && |
| 1638 | test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \ |
| 1639 | git rebase -i --root && |
| 1640 | cp .git/rebase-merge/git-rebase-todo.backup orig && |
| 1641 | test_must_fail env FAKE_LINES="2 3 4" \ |
| 1642 | git rebase --edit-todo 2>actual && |
| 1643 | test_cmp expect actual && |
| 1644 | test_must_fail git rebase --continue 2>actual && |
| 1645 | test_cmp expect.2 actual && |
| 1646 | test_must_fail git rebase --edit-todo && |
| 1647 | cp orig .git/rebase-merge/git-rebase-todo && |
| 1648 | test_must_fail env FAKE_LINES="1 2 3 4" \ |
| 1649 | git rebase --edit-todo 2>actual && |
| 1650 | test_cmp expect.3 actual && |
| 1651 | test_must_fail git rebase --continue 2>actual && |
| 1652 | test_cmp expect.3 actual && |
| 1653 | cp orig .git/rebase-merge/git-rebase-todo && |
| 1654 | FAKE_LINES="1 2 3 4 drop 5" git rebase --edit-todo && |
| 1655 | git rebase --continue 2>actual |
| 1656 | ) && |
| 1657 | test D = $(git cat-file commit HEAD | sed -ne \$p) && |
| 1658 | test_grep \ |
| 1659 | "Successfully rebased and updated refs/heads/missing-commit" \ |
| 1660 | actual |
| 1661 | ' |
| 1662 | |
| 1663 | test_expect_success 'rebase.missingCommitsCheck = error after resolving conflicts' ' |
| 1664 | test_config rebase.missingCommitsCheck error && |
| 1665 | ( |
| 1666 | set_fake_editor && |
| 1667 | FAKE_LINES="drop 1 break 2 3 4" git rebase -i A E |
| 1668 | ) && |
| 1669 | git rebase --edit-todo && |
| 1670 | test_must_fail git rebase --continue && |
| 1671 | echo x >file1 && |
| 1672 | git add file1 && |
| 1673 | git rebase --continue |
| 1674 | ' |
| 1675 | |
| 1676 | test_expect_success 'rebase.missingCommitsCheck = error when editing for a second time' ' |
| 1677 | test_config rebase.missingCommitsCheck error && |
| 1678 | ( |
| 1679 | set_fake_editor && |
| 1680 | FAKE_LINES="1 break 2 3" git rebase -i A D && |
| 1681 | cp .git/rebase-merge/git-rebase-todo todo && |
| 1682 | test_must_fail env FAKE_LINES=2 git rebase --edit-todo && |
| 1683 | GIT_SEQUENCE_EDITOR="cp todo" git rebase --edit-todo && |
| 1684 | git rebase --continue |
| 1685 | ) |
| 1686 | ' |
| 1687 | |
| 1688 | test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' ' |
| 1689 | rebase_setup_and_clean abbrevcmd && |
| 1690 | test_commit "first" file1.txt "first line" first && |
| 1691 | test_commit "second" file1.txt "another line" second && |
| 1692 | test_commit "fixup! first" file2.txt "first line again" first_fixup && |
| 1693 | test_commit "squash! second" file1.txt "another line here" second_squash && |
| 1694 | cat >expected <<-EOF && |
| 1695 | p $(git rev-list --abbrev-commit -1 first) # first |
| 1696 | f $(git rev-list --abbrev-commit -1 first_fixup) # fixup! first |
| 1697 | x git show HEAD |
| 1698 | p $(git rev-list --abbrev-commit -1 second) # second |
| 1699 | s $(git rev-list --abbrev-commit -1 second_squash) # squash! second |
| 1700 | x git show HEAD |
| 1701 | EOF |
| 1702 | git checkout abbrevcmd && |
| 1703 | test_config rebase.abbreviateCommands true && |
| 1704 | ( |
| 1705 | set_cat_todo_editor && |
| 1706 | test_must_fail git rebase -i --exec "git show HEAD" \ |
| 1707 | --autosquash primary >actual |
| 1708 | ) && |
| 1709 | test_cmp expected actual |
| 1710 | ' |
| 1711 | |
| 1712 | test_expect_success 'static check of bad command' ' |
| 1713 | rebase_setup_and_clean bad-cmd && |
| 1714 | ( |
| 1715 | set_fake_editor && |
| 1716 | test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \ |
| 1717 | git rebase -i --root 2>actual && |
| 1718 | test_grep "pickled $(git log --format="%h # %s" -1 primary~1)" \ |
| 1719 | actual && |
| 1720 | test_grep "You can fix this with .git rebase --edit-todo.." \ |
| 1721 | actual && |
| 1722 | FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo |
| 1723 | ) && |
| 1724 | git rebase --continue && |
| 1725 | test E = $(git cat-file commit HEAD | sed -ne \$p) && |
| 1726 | test C = $(git cat-file commit HEAD^ | sed -ne \$p) |
| 1727 | ' |
| 1728 | |
| 1729 | test_expect_success 'the first command cannot be a fixup' ' |
| 1730 | rebase_setup_and_clean fixup-first && |
| 1731 | |
| 1732 | cat >orig <<-EOF && |
| 1733 | fixup $(git log -1 --format="%h %s" B) |
| 1734 | pick $(git log -1 --format="%h %s" C) |
| 1735 | EOF |
| 1736 | |
| 1737 | ( |
| 1738 | set_replace_editor orig && |
| 1739 | test_must_fail git rebase -i A 2>actual |
| 1740 | ) && |
| 1741 | test_grep "cannot .fixup. without a previous commit" actual && |
| 1742 | test_grep "You can fix this with .git rebase --edit-todo.." actual && |
| 1743 | # verify that the todo list has not been truncated |
| 1744 | grep -v "^#" .git/rebase-merge/git-rebase-todo >actual && |
| 1745 | test_cmp orig actual && |
| 1746 | |
| 1747 | test_must_fail git rebase --edit-todo 2>actual && |
| 1748 | test_grep "cannot .fixup. without a previous commit" actual && |
| 1749 | test_grep "You can fix this with .git rebase --edit-todo.." actual && |
| 1750 | # verify that the todo list has not been truncated |
| 1751 | grep -v "^#" .git/rebase-merge/git-rebase-todo >actual && |
| 1752 | test_cmp orig actual |
| 1753 | ' |
| 1754 | |
| 1755 | test_expect_success 'tabs and spaces are accepted in the todolist' ' |
| 1756 | rebase_setup_and_clean indented-comment && |
| 1757 | write_script add-indent.sh <<-\EOF && |
| 1758 | ( |
| 1759 | # Turn single spaces into space/tab mix |
| 1760 | sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1" |
| 1761 | printf "\n\t# comment\n #more\n\t # comment\n" |
| 1762 | ) >"$1.new" |
| 1763 | mv "$1.new" "$1" |
| 1764 | EOF |
| 1765 | ( |
| 1766 | test_set_editor "$(pwd)/add-indent.sh" && |
| 1767 | git rebase -i HEAD^^^ |
| 1768 | ) && |
| 1769 | test E = $(git cat-file commit HEAD | sed -ne \$p) |
| 1770 | ' |
| 1771 | |
| 1772 | test_expect_success 'static check of bad SHA-1' ' |
| 1773 | rebase_setup_and_clean bad-sha && |
| 1774 | ( |
| 1775 | set_fake_editor && |
| 1776 | test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \ |
| 1777 | git rebase -i --root 2>actual && |
| 1778 | test_grep "edit XXXXXXX False commit" actual && |
| 1779 | test_grep "You can fix this with .git rebase --edit-todo.." \ |
| 1780 | actual && |
| 1781 | FAKE_LINES="1 2 4 5 6" git rebase --edit-todo |
| 1782 | ) && |
| 1783 | git rebase --continue && |
| 1784 | test E = $(git cat-file commit HEAD | sed -ne \$p) |
| 1785 | ' |
| 1786 | |
| 1787 | test_expect_success 'editor saves as CR/LF' ' |
| 1788 | git checkout -b with-crlf && |
| 1789 | write_script add-crs.sh <<-\EOF && |
| 1790 | sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new && |
| 1791 | mv -f "$1".new "$1" |
| 1792 | EOF |
| 1793 | ( |
| 1794 | test_set_editor "$(pwd)/add-crs.sh" && |
| 1795 | git rebase -i HEAD^ |
| 1796 | ) |
| 1797 | ' |
| 1798 | |
| 1799 | test_expect_success 'rebase -i --gpg-sign=<key-id>' ' |
| 1800 | test_when_finished "test_might_fail git rebase --abort" && |
| 1801 | ( |
| 1802 | set_fake_editor && |
| 1803 | FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \ |
| 1804 | HEAD^ >out 2>err |
| 1805 | ) && |
| 1806 | test_grep "$SQ-S\"S I Gner\"$SQ" err |
| 1807 | ' |
| 1808 | |
| 1809 | test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' ' |
| 1810 | test_when_finished "test_might_fail git rebase --abort" && |
| 1811 | test_config commit.gpgsign true && |
| 1812 | ( |
| 1813 | set_fake_editor && |
| 1814 | FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \ |
| 1815 | HEAD^ >out 2>err |
| 1816 | ) && |
| 1817 | test_grep "$SQ-S\"S I Gner\"$SQ" err |
| 1818 | ' |
| 1819 | |
| 1820 | test_expect_success 'valid author header after --root swap' ' |
| 1821 | rebase_setup_and_clean author-header no-conflict-branch && |
| 1822 | git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit && |
| 1823 | git cat-file commit HEAD | grep ^author >expected && |
| 1824 | ( |
| 1825 | set_fake_editor && |
| 1826 | FAKE_LINES="5 1" git rebase -i --root |
| 1827 | ) && |
| 1828 | git cat-file commit HEAD^ | grep ^author >actual && |
| 1829 | test_cmp expected actual |
| 1830 | ' |
| 1831 | |
| 1832 | test_expect_success 'valid author header when author contains single quote' ' |
| 1833 | rebase_setup_and_clean author-header no-conflict-branch && |
| 1834 | git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit && |
| 1835 | git cat-file commit HEAD | grep ^author >expected && |
| 1836 | ( |
| 1837 | set_fake_editor && |
| 1838 | FAKE_LINES="2" git rebase -i HEAD~2 |
| 1839 | ) && |
| 1840 | git cat-file commit HEAD | grep ^author >actual && |
| 1841 | test_cmp expected actual |
| 1842 | ' |
| 1843 | |
| 1844 | test_expect_success 'post-commit hook is called' ' |
| 1845 | >actual && |
| 1846 | test_hook post-commit <<-\EOS && |
| 1847 | git rev-parse HEAD >>actual |
| 1848 | EOS |
| 1849 | ( |
| 1850 | set_fake_editor && |
| 1851 | FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E && |
| 1852 | echo x>file3 && |
| 1853 | git add file3 && |
| 1854 | FAKE_COMMIT_MESSAGE=edited git rebase --continue |
| 1855 | ) && |
| 1856 | git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \ |
| 1857 | >expect && |
| 1858 | test_cmp expect actual |
| 1859 | ' |
| 1860 | |
| 1861 | test_expect_success 'correct error message for partial commit after empty pick' ' |
| 1862 | test_when_finished "git rebase --abort" && |
| 1863 | ( |
| 1864 | set_fake_editor && |
| 1865 | FAKE_LINES="2 1 1" && |
| 1866 | export FAKE_LINES && |
| 1867 | test_must_fail git rebase -i A D |
| 1868 | ) && |
| 1869 | echo x >file1 && |
| 1870 | test_must_fail git commit file1 2>err && |
| 1871 | test_grep "cannot do a partial commit during a rebase." err |
| 1872 | ' |
| 1873 | |
| 1874 | test_expect_success 'correct error message for commit --amend after empty pick' ' |
| 1875 | test_when_finished "git rebase --abort" && |
| 1876 | ( |
| 1877 | set_fake_editor && |
| 1878 | FAKE_LINES="1 1" && |
| 1879 | export FAKE_LINES && |
| 1880 | test_must_fail git rebase -i A D |
| 1881 | ) && |
| 1882 | echo x>file1 && |
| 1883 | test_must_fail git commit -a --amend 2>err && |
| 1884 | test_grep "middle of a rebase -- cannot amend." err |
| 1885 | ' |
| 1886 | |
| 1887 | test_expect_success 'todo has correct onto hash' ' |
| 1888 | GIT_SEQUENCE_EDITOR=cat git rebase -i no-conflict-branch~4 no-conflict-branch >actual && |
| 1889 | onto=$(git rev-parse --short HEAD~4) && |
| 1890 | test_grep "^# Rebase ..* onto $onto" actual |
| 1891 | ' |
| 1892 | |
| 1893 | test_expect_success 'ORIG_HEAD is updated correctly' ' |
| 1894 | test_when_finished "git checkout primary && git branch -D test-orig-head" && |
| 1895 | git checkout -b test-orig-head A && |
| 1896 | git commit --allow-empty -m A1 && |
| 1897 | git commit --allow-empty -m A2 && |
| 1898 | git commit --allow-empty -m A3 && |
| 1899 | git commit --allow-empty -m A4 && |
| 1900 | git rebase primary && |
| 1901 | test_cmp_rev ORIG_HEAD test-orig-head@{1} |
| 1902 | ' |
| 1903 | |
| 1904 | test_expect_success '--update-refs adds label and update-ref commands' ' |
| 1905 | git checkout -b update-refs no-conflict-branch && |
| 1906 | git branch -f base HEAD~4 && |
| 1907 | git branch -f first HEAD~3 && |
| 1908 | git branch -f second HEAD~3 && |
| 1909 | git branch -f third HEAD~1 && |
| 1910 | git commit --allow-empty --fixup=third && |
| 1911 | git branch -f is-not-reordered && |
| 1912 | git commit --allow-empty --fixup=HEAD~4 && |
| 1913 | git branch -f shared-tip && |
| 1914 | ( |
| 1915 | set_cat_todo_editor && |
| 1916 | |
| 1917 | cat >expect <<-EOF && |
| 1918 | pick $(git log -1 --format=%h J) # J |
| 1919 | fixup $(git log -1 --format=%h update-refs) # fixup! J # empty |
| 1920 | update-ref refs/heads/second |
| 1921 | update-ref refs/heads/first |
| 1922 | pick $(git log -1 --format=%h K) # K |
| 1923 | pick $(git log -1 --format=%h L) # L |
| 1924 | fixup $(git log -1 --format=%h is-not-reordered) # fixup! L # empty |
| 1925 | update-ref refs/heads/third |
| 1926 | pick $(git log -1 --format=%h M) # M |
| 1927 | update-ref refs/heads/no-conflict-branch |
| 1928 | update-ref refs/heads/is-not-reordered |
| 1929 | update-ref refs/heads/shared-tip |
| 1930 | EOF |
| 1931 | |
| 1932 | test_must_fail git rebase -i --autosquash --update-refs primary >todo && |
| 1933 | test_cmp expect todo && |
| 1934 | |
| 1935 | test_must_fail git -c rebase.autosquash=true \ |
| 1936 | -c rebase.updaterefs=true \ |
| 1937 | rebase -i primary >todo && |
| 1938 | |
| 1939 | test_cmp expect todo |
| 1940 | ) |
| 1941 | ' |
| 1942 | |
| 1943 | test_expect_success '--update-refs adds commands with --rebase-merges' ' |
| 1944 | git checkout -b update-refs-with-merge no-conflict-branch && |
| 1945 | git branch -f base HEAD~4 && |
| 1946 | git branch -f first HEAD~3 && |
| 1947 | git branch -f second HEAD~3 && |
| 1948 | git branch -f third HEAD~1 && |
| 1949 | git merge -m merge branch2 && |
| 1950 | git branch -f merge-branch && |
| 1951 | git commit --fixup=third --allow-empty && |
| 1952 | ( |
| 1953 | set_cat_todo_editor && |
| 1954 | |
| 1955 | cat >expect <<-EOF && |
| 1956 | label onto |
| 1957 | reset onto |
| 1958 | pick $(git log -1 --format=%h branch2~1) # F |
| 1959 | pick $(git log -1 --format=%h branch2) # I |
| 1960 | update-ref refs/heads/branch2 |
| 1961 | label branch2 |
| 1962 | reset onto |
| 1963 | pick $(git log -1 --format=%h refs/heads/second) # J |
| 1964 | update-ref refs/heads/second |
| 1965 | update-ref refs/heads/first |
| 1966 | pick $(git log -1 --format=%h refs/heads/third~1) # K |
| 1967 | pick $(git log -1 --format=%h refs/heads/third) # L |
| 1968 | fixup $(git log -1 --format=%h update-refs-with-merge) # fixup! L # empty |
| 1969 | update-ref refs/heads/third |
| 1970 | pick $(git log -1 --format=%h HEAD~2) # M |
| 1971 | update-ref refs/heads/no-conflict-branch |
| 1972 | merge -C $(git log -1 --format=%h HEAD~1) branch2 # merge |
| 1973 | update-ref refs/heads/merge-branch |
| 1974 | EOF |
| 1975 | |
| 1976 | test_must_fail git rebase -i --autosquash \ |
| 1977 | --rebase-merges=rebase-cousins \ |
| 1978 | --update-refs primary >todo && |
| 1979 | |
| 1980 | test_cmp expect todo && |
| 1981 | |
| 1982 | test_must_fail git -c rebase.autosquash=true \ |
| 1983 | -c rebase.updaterefs=true \ |
| 1984 | rebase -i \ |
| 1985 | --rebase-merges=rebase-cousins \ |
| 1986 | primary >todo && |
| 1987 | |
| 1988 | test_cmp expect todo |
| 1989 | ) |
| 1990 | ' |
| 1991 | |
| 1992 | test_expect_success '--update-refs ignores non-branch decorations' ' |
| 1993 | test_when_finished "git branch -D update-refs" && |
| 1994 | test_when_finished "git checkout primary" && |
| 1995 | git checkout -B update-refs no-conflict-branch && |
| 1996 | ( |
| 1997 | set_cat_todo_editor && |
| 1998 | |
| 1999 | # rebase.instructionFormat=%d loads normal log decorations before |
| 2000 | # --update-refs adds its branch placeholders so we must ignore |
| 2001 | # all non-local decorations. |
| 2002 | test_must_fail git -c rebase.instructionFormat="%s%d" \ |
| 2003 | rebase -i --update-refs HEAD^ >todo |
| 2004 | ) && |
| 2005 | grep ^update-ref todo >actual && |
| 2006 | test_write_lines "update-ref refs/heads/no-conflict-branch" >expect && |
| 2007 | test_cmp expect actual |
| 2008 | ' |
| 2009 | |
| 2010 | test_expect_success '--update-refs updates refs correctly' ' |
| 2011 | git checkout -B update-refs no-conflict-branch && |
| 2012 | git branch -f base HEAD~4 && |
| 2013 | git branch -f first HEAD~3 && |
| 2014 | git branch -f second HEAD~3 && |
| 2015 | git branch -f third HEAD~1 && |
| 2016 | test_commit extra2 fileX && |
| 2017 | git commit --amend --fixup=L && |
| 2018 | |
| 2019 | git rebase -i --autosquash --update-refs primary 2>err && |
| 2020 | |
| 2021 | test_cmp_rev HEAD~3 refs/heads/first && |
| 2022 | test_cmp_rev HEAD~3 refs/heads/second && |
| 2023 | test_cmp_rev HEAD~1 refs/heads/third && |
| 2024 | test_cmp_rev HEAD refs/heads/no-conflict-branch && |
| 2025 | |
| 2026 | q_to_tab >expect <<-\EOF && |
| 2027 | Successfully rebased and updated refs/heads/update-refs. |
| 2028 | Updated the following refs with --update-refs: |
| 2029 | Qrefs/heads/first |
| 2030 | Qrefs/heads/no-conflict-branch |
| 2031 | Qrefs/heads/second |
| 2032 | Qrefs/heads/third |
| 2033 | EOF |
| 2034 | |
| 2035 | # Clear "Rebasing (X/Y)" progress lines and drop leading tabs. |
| 2036 | sed "s/Rebasing.*Successfully/Successfully/g" <err >err.trimmed && |
| 2037 | test_cmp expect err.trimmed |
| 2038 | ' |
| 2039 | |
| 2040 | test_expect_success 'respect user edits to update-ref steps' ' |
| 2041 | git checkout -B update-refs-break no-conflict-branch && |
| 2042 | git branch -f base HEAD~4 && |
| 2043 | git branch -f first HEAD~3 && |
| 2044 | git branch -f second HEAD~3 && |
| 2045 | git branch -f third HEAD~1 && |
| 2046 | git branch -f unseen base && |
| 2047 | |
| 2048 | # First, we will add breaks to the expected todo file |
| 2049 | cat >fake-todo-1 <<-EOF && |
| 2050 | pick $(git rev-parse HEAD~3) |
| 2051 | break |
| 2052 | update-ref refs/heads/second |
| 2053 | update-ref refs/heads/first |
| 2054 | |
| 2055 | pick $(git rev-parse HEAD~2) |
| 2056 | pick $(git rev-parse HEAD~1) |
| 2057 | update-ref refs/heads/third |
| 2058 | |
| 2059 | pick $(git rev-parse HEAD) |
| 2060 | update-ref refs/heads/no-conflict-branch |
| 2061 | EOF |
| 2062 | |
| 2063 | # Second, we will drop some update-refs commands (and move one) |
| 2064 | cat >fake-todo-2 <<-EOF && |
| 2065 | update-ref refs/heads/second |
| 2066 | |
| 2067 | pick $(git rev-parse HEAD~2) |
| 2068 | update-ref refs/heads/third |
| 2069 | pick $(git rev-parse HEAD~1) |
| 2070 | break |
| 2071 | |
| 2072 | pick $(git rev-parse HEAD) |
| 2073 | EOF |
| 2074 | |
| 2075 | # Third, we will: |
| 2076 | # * insert a new one (new-branch), |
| 2077 | # * re-add an old one (first), and |
| 2078 | # * add a second instance of a previously-stored one (second) |
| 2079 | cat >fake-todo-3 <<-EOF && |
| 2080 | update-ref refs/heads/unseen |
| 2081 | update-ref refs/heads/new-branch |
| 2082 | pick $(git rev-parse HEAD) |
| 2083 | update-ref refs/heads/first |
| 2084 | update-ref refs/heads/second |
| 2085 | EOF |
| 2086 | |
| 2087 | ( |
| 2088 | set_replace_editor fake-todo-1 && |
| 2089 | git rebase -i --update-refs primary && |
| 2090 | |
| 2091 | # These branches are currently locked. |
| 2092 | for b in first second third no-conflict-branch |
| 2093 | do |
| 2094 | test_must_fail git branch -f $b base || return 1 |
| 2095 | done && |
| 2096 | |
| 2097 | set_replace_editor fake-todo-2 && |
| 2098 | git rebase --edit-todo && |
| 2099 | |
| 2100 | # These branches are currently locked. |
| 2101 | for b in second third |
| 2102 | do |
| 2103 | test_must_fail git branch -f $b base || return 1 |
| 2104 | done && |
| 2105 | |
| 2106 | # These branches are currently unlocked for checkout. |
| 2107 | for b in first no-conflict-branch |
| 2108 | do |
| 2109 | git worktree add wt-$b $b && |
| 2110 | git worktree remove wt-$b || return 1 |
| 2111 | done && |
| 2112 | |
| 2113 | git rebase --continue && |
| 2114 | |
| 2115 | set_replace_editor fake-todo-3 && |
| 2116 | git rebase --edit-todo && |
| 2117 | |
| 2118 | # These branches are currently locked. |
| 2119 | for b in second third first unseen |
| 2120 | do |
| 2121 | test_must_fail git branch -f $b base || return 1 |
| 2122 | done && |
| 2123 | |
| 2124 | # These branches are currently unlocked for checkout. |
| 2125 | for b in no-conflict-branch |
| 2126 | do |
| 2127 | git worktree add wt-$b $b && |
| 2128 | git worktree remove wt-$b || return 1 |
| 2129 | done && |
| 2130 | |
| 2131 | git rebase --continue |
| 2132 | ) && |
| 2133 | |
| 2134 | test_cmp_rev HEAD~2 refs/heads/third && |
| 2135 | test_cmp_rev HEAD~1 refs/heads/unseen && |
| 2136 | test_cmp_rev HEAD~1 refs/heads/new-branch && |
| 2137 | test_cmp_rev HEAD refs/heads/first && |
| 2138 | test_cmp_rev HEAD refs/heads/second && |
| 2139 | test_cmp_rev HEAD refs/heads/no-conflict-branch |
| 2140 | ' |
| 2141 | |
| 2142 | test_expect_success '--update-refs: all update-ref lines removed' ' |
| 2143 | git checkout -b test-refs-not-removed no-conflict-branch && |
| 2144 | git branch -f base HEAD~4 && |
| 2145 | git branch -f first HEAD~3 && |
| 2146 | git branch -f second HEAD~3 && |
| 2147 | git branch -f third HEAD~1 && |
| 2148 | git branch -f tip && |
| 2149 | |
| 2150 | test_commit test-refs-not-removed && |
| 2151 | git commit --amend --fixup first && |
| 2152 | |
| 2153 | git rev-parse first second third tip no-conflict-branch >expect-oids && |
| 2154 | |
| 2155 | ( |
| 2156 | set_cat_todo_editor && |
| 2157 | test_must_fail git rebase -i --update-refs base >todo.raw && |
| 2158 | sed -e "/^update-ref/d" <todo.raw >todo |
| 2159 | ) && |
| 2160 | ( |
| 2161 | set_replace_editor todo && |
| 2162 | git rebase -i --update-refs base |
| 2163 | ) && |
| 2164 | |
| 2165 | # Ensure refs are not deleted and their OIDs have not changed |
| 2166 | git rev-parse first second third tip no-conflict-branch >actual-oids && |
| 2167 | test_cmp expect-oids actual-oids |
| 2168 | ' |
| 2169 | |
| 2170 | test_expect_success '--update-refs: all update-ref lines removed, then some re-added' ' |
| 2171 | git checkout -b test-refs-not-removed2 no-conflict-branch && |
| 2172 | git branch -f base HEAD~4 && |
| 2173 | git branch -f first HEAD~3 && |
| 2174 | git branch -f second HEAD~3 && |
| 2175 | git branch -f third HEAD~1 && |
| 2176 | git branch -f tip && |
| 2177 | |
| 2178 | test_commit test-refs-not-removed2 && |
| 2179 | git commit --amend --fixup first && |
| 2180 | |
| 2181 | git rev-parse first second third >expect-oids && |
| 2182 | |
| 2183 | ( |
| 2184 | set_cat_todo_editor && |
| 2185 | test_must_fail git rebase -i \ |
| 2186 | --autosquash --update-refs \ |
| 2187 | base >todo.raw && |
| 2188 | sed -e "/^update-ref/d" <todo.raw >todo |
| 2189 | ) && |
| 2190 | |
| 2191 | # Add a break to the end of the todo so we can edit later |
| 2192 | echo "break" >>todo && |
| 2193 | |
| 2194 | ( |
| 2195 | set_replace_editor todo && |
| 2196 | git rebase -i --autosquash --update-refs base && |
| 2197 | echo "update-ref refs/heads/tip" >todo && |
| 2198 | git rebase --edit-todo && |
| 2199 | git rebase --continue |
| 2200 | ) && |
| 2201 | |
| 2202 | # Ensure first/second/third are unchanged, but tip is updated |
| 2203 | git rev-parse first second third >actual-oids && |
| 2204 | test_cmp expect-oids actual-oids && |
| 2205 | test_cmp_rev HEAD tip |
| 2206 | ' |
| 2207 | |
| 2208 | test_expect_success '--update-refs: --edit-todo with no update-ref lines' ' |
| 2209 | git checkout -b test-refs-not-removed3 no-conflict-branch && |
| 2210 | git branch -f base HEAD~4 && |
| 2211 | git branch -f first HEAD~3 && |
| 2212 | git branch -f second HEAD~3 && |
| 2213 | git branch -f third HEAD~1 && |
| 2214 | git branch -f tip && |
| 2215 | |
| 2216 | test_commit test-refs-not-removed3 && |
| 2217 | git commit --amend --fixup first && |
| 2218 | |
| 2219 | git rev-parse first second third tip no-conflict-branch >expect-oids && |
| 2220 | |
| 2221 | ( |
| 2222 | set_cat_todo_editor && |
| 2223 | test_must_fail git rebase -i \ |
| 2224 | --autosquash --update-refs \ |
| 2225 | base >todo.raw && |
| 2226 | sed -e "/^update-ref/d" <todo.raw >todo |
| 2227 | ) && |
| 2228 | |
| 2229 | # Add a break to the beginning of the todo so we can resume with no |
| 2230 | # update-ref lines |
| 2231 | echo "break" >todo.new && |
| 2232 | cat todo >>todo.new && |
| 2233 | |
| 2234 | ( |
| 2235 | set_replace_editor todo.new && |
| 2236 | git rebase -i --autosquash --update-refs base && |
| 2237 | |
| 2238 | # Make no changes when editing so update-refs is still empty |
| 2239 | cat todo >todo.new && |
| 2240 | git rebase --edit-todo && |
| 2241 | git rebase --continue |
| 2242 | ) && |
| 2243 | |
| 2244 | # Ensure refs are not deleted and their OIDs have not changed |
| 2245 | git rev-parse first second third tip no-conflict-branch >actual-oids && |
| 2246 | test_cmp expect-oids actual-oids |
| 2247 | ' |
| 2248 | |
| 2249 | test_expect_success '--update-refs: check failed ref update' ' |
| 2250 | test_when_finished "test_might_fail git rebase --abort" && |
| 2251 | git checkout -B update-refs-error no-conflict-branch && |
| 2252 | git branch -f base HEAD~4 && |
| 2253 | git branch -f first HEAD~3 && |
| 2254 | git branch -f second HEAD~2 && |
| 2255 | git branch -f third HEAD~1 && |
| 2256 | |
| 2257 | cat >fake-todo <<-EOF && |
| 2258 | pick $(git rev-parse HEAD~3) |
| 2259 | break |
| 2260 | update-ref refs/heads/first |
| 2261 | |
| 2262 | pick $(git rev-parse HEAD~2) |
| 2263 | update-ref refs/heads/second |
| 2264 | |
| 2265 | pick $(git rev-parse HEAD~1) |
| 2266 | update-ref refs/heads/third |
| 2267 | |
| 2268 | pick $(git rev-parse HEAD) |
| 2269 | update-ref refs/heads/no-conflict-branch |
| 2270 | EOF |
| 2271 | |
| 2272 | ( |
| 2273 | set_replace_editor fake-todo && |
| 2274 | git rebase -i --update-refs base |
| 2275 | ) && |
| 2276 | |
| 2277 | # At this point, the values of first, second, and third are |
| 2278 | # recorded in the update-refs file. We will force-update the |
| 2279 | # "second" ref, but "git branch -f" will not work because of |
| 2280 | # the lock in the update-refs file. |
| 2281 | git update-ref refs/heads/second third && |
| 2282 | |
| 2283 | test_must_fail git rebase --continue 2>err && |
| 2284 | test_grep "update_ref failed for ref '\''refs/heads/second'\''" err && |
| 2285 | |
| 2286 | q_to_tab >expect <<-\EOF && |
| 2287 | Updated the following refs with --update-refs: |
| 2288 | Qrefs/heads/first |
| 2289 | Qrefs/heads/no-conflict-branch |
| 2290 | Qrefs/heads/third |
| 2291 | Failed to update the following refs with --update-refs: |
| 2292 | Qrefs/heads/second |
| 2293 | EOF |
| 2294 | |
| 2295 | # Clear "Rebasing (X/Y)" progress lines and drop leading tabs. |
| 2296 | tail -n 6 err >err.last && |
| 2297 | sed "s/Rebasing.*Successfully/Successfully/g" <err.last >err.trimmed && |
| 2298 | test_cmp expect err.trimmed |
| 2299 | ' |
| 2300 | |
| 2301 | test_expect_success 'bad labels and refs rejected when parsing todo list' ' |
| 2302 | test_when_finished "test_might_fail git rebase --abort" && |
| 2303 | cat >todo <<-\EOF && |
| 2304 | exec >execed |
| 2305 | label # |
| 2306 | label :invalid |
| 2307 | update-ref :bad |
| 2308 | update-ref topic |
| 2309 | EOF |
| 2310 | rm -f execed && |
| 2311 | ( |
| 2312 | set_replace_editor todo && |
| 2313 | test_must_fail git rebase -i HEAD 2>err |
| 2314 | ) && |
| 2315 | test_grep "'\''#'\'' is not a valid label" err && |
| 2316 | test_grep "'\'':invalid'\'' is not a valid label" err && |
| 2317 | test_grep "'\'':bad'\'' is not a valid refname" err && |
| 2318 | test_grep "update-ref requires a fully qualified refname e.g. refs/heads/topic" \ |
| 2319 | err && |
| 2320 | test_path_is_missing execed |
| 2321 | ' |
| 2322 | |
| 2323 | test_expect_success 'non-merge commands reject merge commits' ' |
| 2324 | test_when_finished "test_might_fail git rebase --abort" && |
| 2325 | git checkout E && |
| 2326 | git merge I && |
| 2327 | oid=$(git rev-parse HEAD) && |
| 2328 | cat >todo <<-EOF && |
| 2329 | pick $oid |
| 2330 | reword $oid |
| 2331 | edit $oid |
| 2332 | fixup $oid |
| 2333 | squash $oid |
| 2334 | drop $oid # acceptable, no advice |
| 2335 | EOF |
| 2336 | ( |
| 2337 | set_replace_editor todo && |
| 2338 | test_must_fail git rebase -i HEAD 2>actual |
| 2339 | ) && |
| 2340 | cat >expect <<-EOF && |
| 2341 | error: ${SQ}pick${SQ} does not accept merge commits |
| 2342 | hint: ${SQ}pick${SQ} does not take a merge commit. If you wanted to |
| 2343 | hint: replay the merge, use ${SQ}merge -C${SQ} on the commit. |
| 2344 | hint: Disable this message with "git config set --global advice.rebaseTodoError false" |
| 2345 | error: invalid line 1: pick $oid |
| 2346 | error: ${SQ}reword${SQ} does not accept merge commits |
| 2347 | hint: ${SQ}reword${SQ} does not take a merge commit. If you wanted to |
| 2348 | hint: replay the merge and reword the commit message, use |
| 2349 | hint: ${SQ}merge -c${SQ} on the commit |
| 2350 | hint: Disable this message with "git config set --global advice.rebaseTodoError false" |
| 2351 | error: invalid line 2: reword $oid |
| 2352 | error: ${SQ}edit${SQ} does not accept merge commits |
| 2353 | hint: ${SQ}edit${SQ} does not take a merge commit. If you wanted to |
| 2354 | hint: replay the merge, use ${SQ}merge -C${SQ} on the commit, and then |
| 2355 | hint: ${SQ}break${SQ} to give the control back to you so that you can |
| 2356 | hint: do ${SQ}git commit --amend && git rebase --continue${SQ}. |
| 2357 | hint: Disable this message with "git config set --global advice.rebaseTodoError false" |
| 2358 | error: invalid line 3: edit $oid |
| 2359 | error: cannot squash merge commit into another commit |
| 2360 | error: invalid line 4: fixup $oid |
| 2361 | error: cannot squash merge commit into another commit |
| 2362 | error: invalid line 5: squash $oid |
| 2363 | You can fix this with ${SQ}git rebase --edit-todo${SQ} and then run ${SQ}git rebase --continue${SQ}. |
| 2364 | Or you can abort the rebase with ${SQ}git rebase --abort${SQ}. |
| 2365 | EOF |
| 2366 | test_cmp expect actual |
| 2367 | ' |
| 2368 | |
| 2369 | # This must be the last test in this file |
| 2370 | test_expect_success '$EDITOR and friends are unchanged' ' |
| 2371 | test_editor_unchanged |
| 2372 | ' |
| 2373 | |
| 2374 | test_done |