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