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