Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t3404-rebase-interactive.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t3404-rebase-interactive.sh` 2374 lines ยท 69335 bytes Raw Blame History 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 ' ' 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 " && 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 ' ' 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 ' ' 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 1224 1225 where ${SQ}${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 and 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 <script && 1315 git fast-import