4097a2d9c6941d4f6c8d7c39f95a446a07cf2cc4
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Johannes E. Schindelin
   4#
   5
   6test_description='git rebase interactive
   7
   8This test runs git rebase "interactively", by faking an edit, and verifies
   9that the result still makes sense.
  10
  11Initial setup:
  12
  13     one - two - three - four (conflict-branch)
  14   /
  15 A - B - C - D - E            (master)
  16 | \
  17 |   F - G - H                (branch1)
  18 |     \
  19 |\      I                    (branch2)
  20 | \
  21 |   J - K - L - M            (no-conflict-branch)
  22  \
  23    N - O - P                 (no-ff-branch)
  24
  25 where A, B, D and G all touch file1, and one, two, three, four all
  26 touch file "conflict".
  27'
  28. ./test-lib.sh
  29
  30. "$TEST_DIRECTORY"/lib-rebase.sh
  31
  32set_fake_editor
  33
  34# WARNING: Modifications to the initial repository can change the SHA ID used
  35# in the expect2 file for the 'stop on conflicting pick' test.
  36
  37test_expect_success 'setup' '
  38        test_commit A file1 &&
  39        test_commit B file1 &&
  40        test_commit C file2 &&
  41        test_commit D file1 &&
  42        test_commit E file3 &&
  43        git checkout -b branch1 A &&
  44        test_commit F file4 &&
  45        test_commit G file1 &&
  46        test_commit H file5 &&
  47        git checkout -b branch2 F &&
  48        test_commit I file6 &&
  49        git checkout -b conflict-branch A &&
  50        test_commit one conflict &&
  51        test_commit two conflict &&
  52        test_commit three conflict &&
  53        test_commit four conflict &&
  54        git checkout -b no-conflict-branch A &&
  55        test_commit J fileJ &&
  56        test_commit K fileK &&
  57        test_commit L fileL &&
  58        test_commit M fileM &&
  59        git checkout -b no-ff-branch A &&
  60        test_commit N fileN &&
  61        test_commit O fileO &&
  62        test_commit P fileP
  63'
  64
  65# "exec" commands are ran with the user shell by default, but this may
  66# be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work
  67# to create a file. Unseting SHELL avoids such non-portable behavior
  68# in tests.
  69SHELL=
  70
  71test_expect_success 'rebase -i with the exec command' '
  72        git checkout master &&
  73        (
  74        FAKE_LINES="1 exec_>touch-one
  75                2 exec_>touch-two exec_false exec_>touch-three
  76                3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
  77        export FAKE_LINES &&
  78        test_must_fail git rebase -i A
  79        ) &&
  80        test_path_is_file touch-one &&
  81        test_path_is_file touch-two &&
  82        test_path_is_missing touch-three " (should have stopped before)" &&
  83        test $(git rev-parse C) = $(git rev-parse HEAD) || {
  84                echo "Stopped at wrong revision:"
  85                echo "($(git describe --tags HEAD) instead of C)"
  86                false
  87        } &&
  88        git rebase --continue &&
  89        test_path_is_file touch-three &&
  90        test_path_is_file "touch-file  name with spaces" &&
  91        test_path_is_file touch-after-semicolon &&
  92        test $(git rev-parse master) = $(git rev-parse HEAD) || {
  93                echo "Stopped at wrong revision:"
  94                echo "($(git describe --tags HEAD) instead of master)"
  95                false
  96        } &&
  97        rm -f touch-*
  98'
  99
 100test_expect_success 'rebase -i with the exec command runs from tree root' '
 101        git checkout master &&
 102        mkdir subdir && (cd subdir &&
 103        FAKE_LINES="1 exec_>touch-subdir" \
 104                git rebase -i HEAD^
 105        ) &&
 106        test_path_is_file touch-subdir &&
 107        rm -fr subdir
 108'
 109
 110test_expect_success 'rebase -i with the exec command checks tree cleanness' '
 111        git checkout master &&
 112        (
 113        FAKE_LINES="exec_echo_foo_>file1 1" &&
 114        export FAKE_LINES &&
 115        test_must_fail git rebase -i HEAD^
 116        ) &&
 117        test $(git rev-parse master^) = $(git rev-parse HEAD) || {
 118                echo "Stopped at wrong revision:"
 119                echo "($(git describe --tags HEAD) instead of master^)"
 120                false
 121        } &&
 122        git reset --hard &&
 123        git rebase --continue
 124'
 125
 126test_expect_success 'no changes are a nop' '
 127        git checkout branch2 &&
 128        git rebase -i F &&
 129        test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
 130        test $(git rev-parse I) = $(git rev-parse HEAD)
 131'
 132
 133test_expect_success 'test the [branch] option' '
 134        git checkout -b dead-end &&
 135        git rm file6 &&
 136        git commit -m "stop here" &&
 137        git rebase -i F branch2 &&
 138        test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
 139        test $(git rev-parse I) = $(git rev-parse branch2) &&
 140        test $(git rev-parse I) = $(git rev-parse HEAD)
 141'
 142
 143test_expect_success 'test --onto <branch>' '
 144        git checkout -b test-onto branch2 &&
 145        git rebase -i --onto branch1 F &&
 146        test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
 147        test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
 148        test $(git rev-parse I) = $(git rev-parse branch2)
 149'
 150
 151test_expect_success 'rebase on top of a non-conflicting commit' '
 152        git checkout branch1 &&
 153        git tag original-branch1 &&
 154        git rebase -i branch2 &&
 155        test file6 = $(git diff --name-only original-branch1) &&
 156        test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
 157        test $(git rev-parse I) = $(git rev-parse branch2) &&
 158        test $(git rev-parse I) = $(git rev-parse HEAD~2)
 159'
 160
 161test_expect_success 'reflog for the branch shows state before rebase' '
 162        test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
 163'
 164
 165test_expect_success 'exchange two commits' '
 166        FAKE_LINES="2 1" git rebase -i HEAD~2 &&
 167        test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
 168        test G = $(git cat-file commit HEAD | sed -ne \$p)
 169'
 170
 171cat > expect << EOF
 172diff --git a/file1 b/file1
 173index f70f10e..fd79235 100644
 174--- a/file1
 175+++ b/file1
 176@@ -1 +1 @@
 177-A
 178+G
 179EOF
 180
 181cat > expect2 << EOF
 182<<<<<<< HEAD
 183D
 184=======
 185G
 186>>>>>>> 5d18e54... G
 187EOF
 188
 189test_expect_success 'stop on conflicting pick' '
 190        git tag new-branch1 &&
 191        test_must_fail git rebase -i master &&
 192        test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
 193        test_cmp expect .git/rebase-merge/patch &&
 194        test_cmp expect2 file1 &&
 195        test "$(git diff --name-status |
 196                sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
 197        test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
 198        test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
 199'
 200
 201test_expect_success 'abort' '
 202        git rebase --abort &&
 203        test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
 204        test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
 205        test_path_is_missing .git/rebase-merge
 206'
 207
 208test_expect_success 'abort with error when new base cannot be checked out' '
 209        git rm --cached file1 &&
 210        git commit -m "remove file in base" &&
 211        test_must_fail git rebase -i master > output 2>&1 &&
 212        grep "The following untracked working tree files would be overwritten by checkout:" \
 213                output &&
 214        grep "file1" output &&
 215        test_path_is_missing .git/rebase-merge &&
 216        git reset --hard HEAD^
 217'
 218
 219test_expect_success 'retain authorship' '
 220        echo A > file7 &&
 221        git add file7 &&
 222        test_tick &&
 223        GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
 224        git tag twerp &&
 225        git rebase -i --onto master HEAD^ &&
 226        git show HEAD | grep "^Author: Twerp Snog"
 227'
 228
 229test_expect_success 'squash' '
 230        git reset --hard twerp &&
 231        echo B > file7 &&
 232        test_tick &&
 233        GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
 234        echo "******************************" &&
 235        FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
 236                git rebase -i --onto master HEAD~2 &&
 237        test B = $(cat file7) &&
 238        test $(git rev-parse HEAD^) = $(git rev-parse master)
 239'
 240
 241test_expect_success 'retain authorship when squashing' '
 242        git show HEAD | grep "^Author: Twerp Snog"
 243'
 244
 245test_expect_success '-p handles "no changes" gracefully' '
 246        HEAD=$(git rev-parse HEAD) &&
 247        git rebase -i -p HEAD^ &&
 248        git update-index --refresh &&
 249        git diff-files --quiet &&
 250        git diff-index --quiet --cached HEAD -- &&
 251        test $HEAD = $(git rev-parse HEAD)
 252'
 253
 254test_expect_failure 'exchange two commits with -p' '
 255        FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
 256        test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
 257        test G = $(git cat-file commit HEAD | sed -ne \$p)
 258'
 259
 260test_expect_success 'preserve merges with -p' '
 261        git checkout -b to-be-preserved master^ &&
 262        : > unrelated-file &&
 263        git add unrelated-file &&
 264        test_tick &&
 265        git commit -m "unrelated" &&
 266        git checkout -b another-branch master &&
 267        echo B > file1 &&
 268        test_tick &&
 269        git commit -m J file1 &&
 270        test_tick &&
 271        git merge to-be-preserved &&
 272        echo C > file1 &&
 273        test_tick &&
 274        git commit -m K file1 &&
 275        echo D > file1 &&
 276        test_tick &&
 277        git commit -m L1 file1 &&
 278        git checkout HEAD^ &&
 279        echo 1 > unrelated-file &&
 280        test_tick &&
 281        git commit -m L2 unrelated-file &&
 282        test_tick &&
 283        git merge another-branch &&
 284        echo E > file1 &&
 285        test_tick &&
 286        git commit -m M file1 &&
 287        git checkout -b to-be-rebased &&
 288        test_tick &&
 289        git rebase -i -p --onto branch1 master &&
 290        git update-index --refresh &&
 291        git diff-files --quiet &&
 292        git diff-index --quiet --cached HEAD -- &&
 293        test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
 294        test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
 295        test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
 296        test $(git show HEAD~5:file1) = B &&
 297        test $(git show HEAD~3:file1) = C &&
 298        test $(git show HEAD:file1) = E &&
 299        test $(git show HEAD:unrelated-file) = 1
 300'
 301
 302test_expect_success 'edit ancestor with -p' '
 303        FAKE_LINES="1 edit 2 3 4" git rebase -i -p HEAD~3 &&
 304        echo 2 > unrelated-file &&
 305        test_tick &&
 306        git commit -m L2-modified --amend unrelated-file &&
 307        git rebase --continue &&
 308        git update-index --refresh &&
 309        git diff-files --quiet &&
 310        git diff-index --quiet --cached HEAD -- &&
 311        test $(git show HEAD:unrelated-file) = 2
 312'
 313
 314test_expect_success '--continue tries to commit' '
 315        test_tick &&
 316        test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
 317        echo resolved > file1 &&
 318        git add file1 &&
 319        FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
 320        test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
 321        git show HEAD | grep chouette
 322'
 323
 324test_expect_success 'verbose flag is heeded, even after --continue' '
 325        git reset --hard HEAD@{1} &&
 326        test_tick &&
 327        test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
 328        echo resolved > file1 &&
 329        git add file1 &&
 330        git rebase --continue > output &&
 331        grep "^ file1 |    2 +-$" output
 332'
 333
 334test_expect_success 'multi-squash only fires up editor once' '
 335        base=$(git rev-parse HEAD~4) &&
 336        FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
 337                EXPECT_HEADER_COUNT=4 \
 338                git rebase -i $base &&
 339        test $base = $(git rev-parse HEAD^) &&
 340        test 1 = $(git show | grep ONCE | wc -l)
 341'
 342
 343test_expect_success 'multi-fixup does not fire up editor' '
 344        git checkout -b multi-fixup E &&
 345        base=$(git rev-parse HEAD~4) &&
 346        FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
 347                git rebase -i $base &&
 348        test $base = $(git rev-parse HEAD^) &&
 349        test 0 = $(git show | grep NEVER | wc -l) &&
 350        git checkout to-be-rebased &&
 351        git branch -D multi-fixup
 352'
 353
 354test_expect_success 'commit message used after conflict' '
 355        git checkout -b conflict-fixup conflict-branch &&
 356        base=$(git rev-parse HEAD~4) &&
 357        (
 358                FAKE_LINES="1 fixup 3 fixup 4" &&
 359                export FAKE_LINES &&
 360                test_must_fail git rebase -i $base
 361        ) &&
 362        echo three > conflict &&
 363        git add conflict &&
 364        FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
 365                git rebase --continue &&
 366        test $base = $(git rev-parse HEAD^) &&
 367        test 1 = $(git show | grep ONCE | wc -l) &&
 368        git checkout to-be-rebased &&
 369        git branch -D conflict-fixup
 370'
 371
 372test_expect_success 'commit message retained after conflict' '
 373        git checkout -b conflict-squash conflict-branch &&
 374        base=$(git rev-parse HEAD~4) &&
 375        (
 376                FAKE_LINES="1 fixup 3 squash 4" &&
 377                export FAKE_LINES &&
 378                test_must_fail git rebase -i $base
 379        ) &&
 380        echo three > conflict &&
 381        git add conflict &&
 382        FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
 383                git rebase --continue &&
 384        test $base = $(git rev-parse HEAD^) &&
 385        test 2 = $(git show | grep TWICE | wc -l) &&
 386        git checkout to-be-rebased &&
 387        git branch -D conflict-squash
 388'
 389
 390cat > expect-squash-fixup << EOF
 391B
 392
 393D
 394
 395ONCE
 396EOF
 397
 398test_expect_success 'squash and fixup generate correct log messages' '
 399        git checkout -b squash-fixup E &&
 400        base=$(git rev-parse HEAD~4) &&
 401        FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
 402                EXPECT_HEADER_COUNT=4 \
 403                git rebase -i $base &&
 404        git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
 405        test_cmp expect-squash-fixup actual-squash-fixup &&
 406        git checkout to-be-rebased &&
 407        git branch -D squash-fixup
 408'
 409
 410test_expect_success 'squash ignores comments' '
 411        git checkout -b skip-comments E &&
 412        base=$(git rev-parse HEAD~4) &&
 413        FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
 414                EXPECT_HEADER_COUNT=4 \
 415                git rebase -i $base &&
 416        test $base = $(git rev-parse HEAD^) &&
 417        test 1 = $(git show | grep ONCE | wc -l) &&
 418        git checkout to-be-rebased &&
 419        git branch -D skip-comments
 420'
 421
 422test_expect_success 'squash ignores blank lines' '
 423        git checkout -b skip-blank-lines E &&
 424        base=$(git rev-parse HEAD~4) &&
 425        FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
 426                EXPECT_HEADER_COUNT=4 \
 427                git rebase -i $base &&
 428        test $base = $(git rev-parse HEAD^) &&
 429        test 1 = $(git show | grep ONCE | wc -l) &&
 430        git checkout to-be-rebased &&
 431        git branch -D skip-blank-lines
 432'
 433
 434test_expect_success 'squash works as expected' '
 435        git checkout -b squash-works no-conflict-branch &&
 436        one=$(git rev-parse HEAD~3) &&
 437        FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
 438                git rebase -i HEAD~3 &&
 439        test $one = $(git rev-parse HEAD~2)
 440'
 441
 442test_expect_success 'interrupted squash works as expected' '
 443        git checkout -b interrupted-squash conflict-branch &&
 444        one=$(git rev-parse HEAD~3) &&
 445        (
 446                FAKE_LINES="1 squash 3 2" &&
 447                export FAKE_LINES &&
 448                test_must_fail git rebase -i HEAD~3
 449        ) &&
 450        (echo one; echo two; echo four) > conflict &&
 451        git add conflict &&
 452        test_must_fail git rebase --continue &&
 453        echo resolved > conflict &&
 454        git add conflict &&
 455        git rebase --continue &&
 456        test $one = $(git rev-parse HEAD~2)
 457'
 458
 459test_expect_success 'interrupted squash works as expected (case 2)' '
 460        git checkout -b interrupted-squash2 conflict-branch &&
 461        one=$(git rev-parse HEAD~3) &&
 462        (
 463                FAKE_LINES="3 squash 1 2" &&
 464                export FAKE_LINES &&
 465                test_must_fail git rebase -i HEAD~3
 466        ) &&
 467        (echo one; echo four) > conflict &&
 468        git add conflict &&
 469        test_must_fail git rebase --continue &&
 470        (echo one; echo two; echo four) > conflict &&
 471        git add conflict &&
 472        test_must_fail git rebase --continue &&
 473        echo resolved > conflict &&
 474        git add conflict &&
 475        git rebase --continue &&
 476        test $one = $(git rev-parse HEAD~2)
 477'
 478
 479test_expect_success 'ignore patch if in upstream' '
 480        HEAD=$(git rev-parse HEAD) &&
 481        git checkout -b has-cherry-picked HEAD^ &&
 482        echo unrelated > file7 &&
 483        git add file7 &&
 484        test_tick &&
 485        git commit -m "unrelated change" &&
 486        git cherry-pick $HEAD &&
 487        EXPECT_COUNT=1 git rebase -i $HEAD &&
 488        test $HEAD = $(git rev-parse HEAD^)
 489'
 490
 491test_expect_success '--continue tries to commit, even for "edit"' '
 492        parent=$(git rev-parse HEAD^) &&
 493        test_tick &&
 494        FAKE_LINES="edit 1" git rebase -i HEAD^ &&
 495        echo edited > file7 &&
 496        git add file7 &&
 497        FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
 498        test edited = $(git show HEAD:file7) &&
 499        git show HEAD | grep chouette &&
 500        test $parent = $(git rev-parse HEAD^)
 501'
 502
 503test_expect_success 'aborted --continue does not squash commits after "edit"' '
 504        old=$(git rev-parse HEAD) &&
 505        test_tick &&
 506        FAKE_LINES="edit 1" git rebase -i HEAD^ &&
 507        echo "edited again" > file7 &&
 508        git add file7 &&
 509        (
 510                FAKE_COMMIT_MESSAGE=" " &&
 511                export FAKE_COMMIT_MESSAGE &&
 512                test_must_fail git rebase --continue
 513        ) &&
 514        test $old = $(git rev-parse HEAD) &&
 515        git rebase --abort
 516'
 517
 518test_expect_success 'auto-amend only edited commits after "edit"' '
 519        test_tick &&
 520        FAKE_LINES="edit 1" git rebase -i HEAD^ &&
 521        echo "edited again" > file7 &&
 522        git add file7 &&
 523        FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
 524        echo "and again" > file7 &&
 525        git add file7 &&
 526        test_tick &&
 527        (
 528                FAKE_COMMIT_MESSAGE="and again" &&
 529                export FAKE_COMMIT_MESSAGE &&
 530                test_must_fail git rebase --continue
 531        ) &&
 532        git rebase --abort
 533'
 534
 535test_expect_success 'rebase a detached HEAD' '
 536        grandparent=$(git rev-parse HEAD~2) &&
 537        git checkout $(git rev-parse HEAD) &&
 538        test_tick &&
 539        FAKE_LINES="2 1" git rebase -i HEAD~2 &&
 540        test $grandparent = $(git rev-parse HEAD~2)
 541'
 542
 543test_expect_success 'rebase a commit violating pre-commit' '
 544
 545        mkdir -p .git/hooks &&
 546        PRE_COMMIT=.git/hooks/pre-commit &&
 547        echo "#!/bin/sh" > $PRE_COMMIT &&
 548        echo "test -z \"\$(git diff --cached --check)\"" >> $PRE_COMMIT &&
 549        chmod a+x $PRE_COMMIT &&
 550        echo "monde! " >> file1 &&
 551        test_tick &&
 552        test_must_fail git commit -m doesnt-verify file1 &&
 553        git commit -m doesnt-verify --no-verify file1 &&
 554        test_tick &&
 555        FAKE_LINES=2 git rebase -i HEAD~2
 556
 557'
 558
 559test_expect_success 'rebase with a file named HEAD in worktree' '
 560
 561        rm -fr .git/hooks &&
 562        git reset --hard &&
 563        git checkout -b branch3 A &&
 564
 565        (
 566                GIT_AUTHOR_NAME="Squashed Away" &&
 567                export GIT_AUTHOR_NAME &&
 568                >HEAD &&
 569                git add HEAD &&
 570                git commit -m "Add head" &&
 571                >BODY &&
 572                git add BODY &&
 573                git commit -m "Add body"
 574        ) &&
 575
 576        FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
 577        test "$(git show -s --pretty=format:%an)" = "Squashed Away"
 578
 579'
 580
 581test_expect_success 'do "noop" when there is nothing to cherry-pick' '
 582
 583        git checkout -b branch4 HEAD &&
 584        GIT_EDITOR=: git commit --amend \
 585                --author="Somebody else <somebody@else.com>" &&
 586        test $(git rev-parse branch3) != $(git rev-parse branch4) &&
 587        git rebase -i branch3 &&
 588        test $(git rev-parse branch3) = $(git rev-parse branch4)
 589
 590'
 591
 592test_expect_success 'submodule rebase setup' '
 593        git checkout A &&
 594        mkdir sub &&
 595        (
 596                cd sub && git init && >elif &&
 597                git add elif && git commit -m "submodule initial"
 598        ) &&
 599        echo 1 >file1 &&
 600        git add file1 sub &&
 601        test_tick &&
 602        git commit -m "One" &&
 603        echo 2 >file1 &&
 604        test_tick &&
 605        git commit -a -m "Two" &&
 606        (
 607                cd sub && echo 3 >elif &&
 608                git commit -a -m "submodule second"
 609        ) &&
 610        test_tick &&
 611        git commit -a -m "Three changes submodule"
 612'
 613
 614test_expect_success 'submodule rebase -i' '
 615        FAKE_LINES="1 squash 2 3" git rebase -i A
 616'
 617
 618test_expect_success 'avoid unnecessary reset' '
 619        git checkout master &&
 620        test-chmtime =123456789 file3 &&
 621        git update-index --refresh &&
 622        HEAD=$(git rev-parse HEAD) &&
 623        git rebase -i HEAD~4 &&
 624        test $HEAD = $(git rev-parse HEAD) &&
 625        MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
 626        test 123456789 = $MTIME
 627'
 628
 629test_expect_success 'reword' '
 630        git checkout -b reword-branch master &&
 631        FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
 632        git show HEAD | grep "E changed" &&
 633        test $(git rev-parse master) != $(git rev-parse HEAD) &&
 634        test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
 635        FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
 636        git show HEAD^ | grep "D changed" &&
 637        FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
 638        git show HEAD~3 | grep "B changed" &&
 639        FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
 640        git show HEAD~2 | grep "C changed"
 641'
 642
 643test_expect_success 'rebase -i can copy notes' '
 644        git config notes.rewrite.rebase true &&
 645        git config notes.rewriteRef "refs/notes/*" &&
 646        test_commit n1 &&
 647        test_commit n2 &&
 648        test_commit n3 &&
 649        git notes add -m"a note" n3 &&
 650        git rebase --onto n1 n2 &&
 651        test "a note" = "$(git notes show HEAD)"
 652'
 653
 654cat >expect <<EOF
 655an earlier note
 656a note
 657EOF
 658
 659test_expect_success 'rebase -i can copy notes over a fixup' '
 660        git reset --hard n3 &&
 661        git notes add -m"an earlier note" n2 &&
 662        GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
 663        git notes show > output &&
 664        test_cmp expect output
 665'
 666
 667test_expect_success 'rebase while detaching HEAD' '
 668        git symbolic-ref HEAD &&
 669        grandparent=$(git rev-parse HEAD~2) &&
 670        test_tick &&
 671        FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
 672        test $grandparent = $(git rev-parse HEAD~2) &&
 673        test_must_fail git symbolic-ref HEAD
 674'
 675
 676test_tick # Ensure that the rebased commits get a different timestamp.
 677test_expect_success 'always cherry-pick with --no-ff' '
 678        git checkout no-ff-branch &&
 679        git tag original-no-ff-branch &&
 680        git rebase -i --no-ff A &&
 681        touch empty &&
 682        for p in 0 1 2
 683        do
 684                test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
 685                git diff HEAD~$p original-no-ff-branch~$p > out &&
 686                test_cmp empty out
 687        done &&
 688        test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
 689        git diff HEAD~3 original-no-ff-branch~3 > out &&
 690        test_cmp empty out
 691'
 692
 693test_expect_success 'set up commits with funny messages' '
 694        git checkout -b funny A &&
 695        echo >>file1 &&
 696        test_tick &&
 697        git commit -a -m "end with slash\\" &&
 698        echo >>file1 &&
 699        test_tick &&
 700        git commit -a -m "something (\000) that looks like octal" &&
 701        echo >>file1 &&
 702        test_tick &&
 703        git commit -a -m "something (\n) that looks like a newline" &&
 704        echo >>file1 &&
 705        test_tick &&
 706        git commit -a -m "another commit"
 707'
 708
 709test_expect_success 'rebase-i history with funny messages' '
 710        git rev-list A..funny >expect &&
 711        test_tick &&
 712        FAKE_LINES="1 2 3 4" git rebase -i A &&
 713        git rev-list A.. >actual &&
 714        test_cmp expect actual
 715'
 716
 717test_done