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