t / t3404-rebase-interactive.shon commit Merge branch 'jk/delta-chain-limit' (538569b)
   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
  32# WARNING: Modifications to the initial repository can change the SHA ID used
  33# in the expect2 file for the 'stop on conflicting pick' test.
  34
  35test_expect_success 'setup' '
  36        test_commit A file1 &&
  37        test_commit B file1 &&
  38        test_commit C file2 &&
  39        test_commit D file1 &&
  40        test_commit E file3 &&
  41        git checkout -b branch1 A &&
  42        test_commit F file4 &&
  43        test_commit G file1 &&
  44        test_commit H file5 &&
  45        git checkout -b branch2 F &&
  46        test_commit I file6 &&
  47        git checkout -b conflict-branch A &&
  48        test_commit one conflict &&
  49        test_commit two conflict &&
  50        test_commit three conflict &&
  51        test_commit four conflict &&
  52        git checkout -b no-conflict-branch A &&
  53        test_commit J fileJ &&
  54        test_commit K fileK &&
  55        test_commit L fileL &&
  56        test_commit M fileM &&
  57        git checkout -b no-ff-branch A &&
  58        test_commit N fileN &&
  59        test_commit O fileO &&
  60        test_commit P fileP
  61'
  62
  63# "exec" commands are run with the user shell by default, but this may
  64# be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work
  65# to create a file. Unsetting SHELL avoids such non-portable behavior
  66# in tests. It must be exported for it to take effect where needed.
  67SHELL=
  68export SHELL
  69
  70test_expect_success 'rebase --keep-empty' '
  71        git checkout -b emptybranch master &&
  72        git commit --allow-empty -m "empty" &&
  73        git rebase --keep-empty -i HEAD~2 &&
  74        git log --oneline >actual &&
  75        test_line_count = 6 actual
  76'
  77
  78test_expect_success 'rebase -i with the exec command' '
  79        git checkout master &&
  80        (
  81        set_fake_editor &&
  82        FAKE_LINES="1 exec_>touch-one
  83                2 exec_>touch-two exec_false exec_>touch-three
  84                3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
  85        export FAKE_LINES &&
  86        test_must_fail git rebase -i A
  87        ) &&
  88        test_path_is_file touch-one &&
  89        test_path_is_file touch-two &&
  90        test_path_is_missing touch-three " (should have stopped before)" &&
  91        test_cmp_rev C HEAD &&
  92        git rebase --continue &&
  93        test_path_is_file touch-three &&
  94        test_path_is_file "touch-file  name with spaces" &&
  95        test_path_is_file touch-after-semicolon &&
  96        test_cmp_rev master HEAD &&
  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        set_fake_editor &&
 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        set_fake_editor &&
 114        test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^ &&
 115        test_cmp_rev master^ HEAD &&
 116        git reset --hard &&
 117        git rebase --continue
 118'
 119
 120test_expect_success 'rebase -i with exec of inexistent command' '
 121        git checkout master &&
 122        test_when_finished "git rebase --abort" &&
 123        set_fake_editor &&
 124        test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
 125        git rebase -i HEAD^ >actual 2>&1 &&
 126        ! grep "Maybe git-rebase is broken" actual
 127'
 128
 129test_expect_success 'no changes are a nop' '
 130        git checkout branch2 &&
 131        set_fake_editor &&
 132        git rebase -i F &&
 133        test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
 134        test $(git rev-parse I) = $(git rev-parse HEAD)
 135'
 136
 137test_expect_success 'test the [branch] option' '
 138        git checkout -b dead-end &&
 139        git rm file6 &&
 140        git commit -m "stop here" &&
 141        set_fake_editor &&
 142        git rebase -i F branch2 &&
 143        test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
 144        test $(git rev-parse I) = $(git rev-parse branch2) &&
 145        test $(git rev-parse I) = $(git rev-parse HEAD)
 146'
 147
 148test_expect_success 'test --onto <branch>' '
 149        git checkout -b test-onto branch2 &&
 150        set_fake_editor &&
 151        git rebase -i --onto branch1 F &&
 152        test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
 153        test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
 154        test $(git rev-parse I) = $(git rev-parse branch2)
 155'
 156
 157test_expect_success 'rebase on top of a non-conflicting commit' '
 158        git checkout branch1 &&
 159        git tag original-branch1 &&
 160        set_fake_editor &&
 161        git rebase -i branch2 &&
 162        test file6 = $(git diff --name-only original-branch1) &&
 163        test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
 164        test $(git rev-parse I) = $(git rev-parse branch2) &&
 165        test $(git rev-parse I) = $(git rev-parse HEAD~2)
 166'
 167
 168test_expect_success 'reflog for the branch shows state before rebase' '
 169        test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
 170'
 171
 172test_expect_success 'exchange two commits' '
 173        set_fake_editor &&
 174        FAKE_LINES="2 1" git rebase -i HEAD~2 &&
 175        test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
 176        test G = $(git cat-file commit HEAD | sed -ne \$p)
 177'
 178
 179cat > expect << EOF
 180diff --git a/file1 b/file1
 181index f70f10e..fd79235 100644
 182--- a/file1
 183+++ b/file1
 184@@ -1 +1 @@
 185-A
 186+G
 187EOF
 188
 189cat > expect2 << EOF
 190<<<<<<< HEAD
 191D
 192=======
 193G
 194>>>>>>> 5d18e54... G
 195EOF
 196
 197test_expect_success 'stop on conflicting pick' '
 198        git tag new-branch1 &&
 199        set_fake_editor &&
 200        test_must_fail git rebase -i master &&
 201        test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
 202        test_cmp expect .git/rebase-merge/patch &&
 203        test_cmp expect2 file1 &&
 204        test "$(git diff --name-status |
 205                sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
 206        test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
 207        test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
 208'
 209
 210test_expect_success 'abort' '
 211        git rebase --abort &&
 212        test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
 213        test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
 214        test_path_is_missing .git/rebase-merge
 215'
 216
 217test_expect_success 'abort with error when new base cannot be checked out' '
 218        git rm --cached file1 &&
 219        git commit -m "remove file in base" &&
 220        set_fake_editor &&
 221        test_must_fail git rebase -i master > output 2>&1 &&
 222        test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
 223                output &&
 224        test_i18ngrep "file1" output &&
 225        test_path_is_missing .git/rebase-merge &&
 226        git reset --hard HEAD^
 227'
 228
 229test_expect_success 'retain authorship' '
 230        echo A > file7 &&
 231        git add file7 &&
 232        test_tick &&
 233        GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
 234        git tag twerp &&
 235        set_fake_editor &&
 236        git rebase -i --onto master HEAD^ &&
 237        git show HEAD | grep "^Author: Twerp Snog"
 238'
 239
 240test_expect_success 'retain authorship w/ conflicts' '
 241        git reset --hard twerp &&
 242        test_commit a conflict a conflict-a &&
 243        git reset --hard twerp &&
 244        GIT_AUTHOR_NAME=AttributeMe \
 245        test_commit b conflict b conflict-b &&
 246        set_fake_editor &&
 247        test_must_fail git rebase -i conflict-a &&
 248        echo resolved >conflict &&
 249        git add conflict &&
 250        git rebase --continue &&
 251        test $(git rev-parse conflict-a^0) = $(git rev-parse HEAD^) &&
 252        git show >out &&
 253        grep AttributeMe out
 254'
 255
 256test_expect_success 'squash' '
 257        git reset --hard twerp &&
 258        echo B > file7 &&
 259        test_tick &&
 260        GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
 261        echo "******************************" &&
 262        set_fake_editor &&
 263        FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
 264                git rebase -i --onto master HEAD~2 &&
 265        test B = $(cat file7) &&
 266        test $(git rev-parse HEAD^) = $(git rev-parse master)
 267'
 268
 269test_expect_success 'retain authorship when squashing' '
 270        git show HEAD | grep "^Author: Twerp Snog"
 271'
 272
 273test_expect_success '-p handles "no changes" gracefully' '
 274        HEAD=$(git rev-parse HEAD) &&
 275        set_fake_editor &&
 276        git rebase -i -p HEAD^ &&
 277        git update-index --refresh &&
 278        git diff-files --quiet &&
 279        git diff-index --quiet --cached HEAD -- &&
 280        test $HEAD = $(git rev-parse HEAD)
 281'
 282
 283test_expect_failure 'exchange two commits with -p' '
 284        git checkout H &&
 285        set_fake_editor &&
 286        FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
 287        test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
 288        test G = $(git cat-file commit HEAD | sed -ne \$p)
 289'
 290
 291test_expect_success 'preserve merges with -p' '
 292        git checkout -b to-be-preserved master^ &&
 293        : > unrelated-file &&
 294        git add unrelated-file &&
 295        test_tick &&
 296        git commit -m "unrelated" &&
 297        git checkout -b another-branch master &&
 298        echo B > file1 &&
 299        test_tick &&
 300        git commit -m J file1 &&
 301        test_tick &&
 302        git merge to-be-preserved &&
 303        echo C > file1 &&
 304        test_tick &&
 305        git commit -m K file1 &&
 306        echo D > file1 &&
 307        test_tick &&
 308        git commit -m L1 file1 &&
 309        git checkout HEAD^ &&
 310        echo 1 > unrelated-file &&
 311        test_tick &&
 312        git commit -m L2 unrelated-file &&
 313        test_tick &&
 314        git merge another-branch &&
 315        echo E > file1 &&
 316        test_tick &&
 317        git commit -m M file1 &&
 318        git checkout -b to-be-rebased &&
 319        test_tick &&
 320        set_fake_editor &&
 321        git rebase -i -p --onto branch1 master &&
 322        git update-index --refresh &&
 323        git diff-files --quiet &&
 324        git diff-index --quiet --cached HEAD -- &&
 325        test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
 326        test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
 327        test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
 328        test $(git show HEAD~5:file1) = B &&
 329        test $(git show HEAD~3:file1) = C &&
 330        test $(git show HEAD:file1) = E &&
 331        test $(git show HEAD:unrelated-file) = 1
 332'
 333
 334test_expect_success 'edit ancestor with -p' '
 335        set_fake_editor &&
 336        FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
 337        echo 2 > unrelated-file &&
 338        test_tick &&
 339        git commit -m L2-modified --amend unrelated-file &&
 340        git rebase --continue &&
 341        git update-index --refresh &&
 342        git diff-files --quiet &&
 343        git diff-index --quiet --cached HEAD -- &&
 344        test $(git show HEAD:unrelated-file) = 2
 345'
 346
 347test_expect_success '--continue tries to commit' '
 348        test_tick &&
 349        set_fake_editor &&
 350        test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
 351        echo resolved > file1 &&
 352        git add file1 &&
 353        FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
 354        test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
 355        git show HEAD | grep chouette
 356'
 357
 358test_expect_success 'verbose flag is heeded, even after --continue' '
 359        git reset --hard master@{1} &&
 360        test_tick &&
 361        set_fake_editor &&
 362        test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
 363        echo resolved > file1 &&
 364        git add file1 &&
 365        git rebase --continue > output &&
 366        grep "^ file1 | 2 +-$" output
 367'
 368
 369test_expect_success 'multi-squash only fires up editor once' '
 370        base=$(git rev-parse HEAD~4) &&
 371        set_fake_editor &&
 372        FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
 373                EXPECT_HEADER_COUNT=4 \
 374                git rebase -i $base &&
 375        test $base = $(git rev-parse HEAD^) &&
 376        test 1 = $(git show | grep ONCE | wc -l)
 377'
 378
 379test_expect_success 'multi-fixup does not fire up editor' '
 380        git checkout -b multi-fixup E &&
 381        base=$(git rev-parse HEAD~4) &&
 382        set_fake_editor &&
 383        FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
 384                git rebase -i $base &&
 385        test $base = $(git rev-parse HEAD^) &&
 386        test 0 = $(git show | grep NEVER | wc -l) &&
 387        git checkout to-be-rebased &&
 388        git branch -D multi-fixup
 389'
 390
 391test_expect_success 'commit message used after conflict' '
 392        git checkout -b conflict-fixup conflict-branch &&
 393        base=$(git rev-parse HEAD~4) &&
 394        set_fake_editor &&
 395        test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base &&
 396        echo three > conflict &&
 397        git add conflict &&
 398        FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
 399                git rebase --continue &&
 400        test $base = $(git rev-parse HEAD^) &&
 401        test 1 = $(git show | grep ONCE | wc -l) &&
 402        git checkout to-be-rebased &&
 403        git branch -D conflict-fixup
 404'
 405
 406test_expect_success 'commit message retained after conflict' '
 407        git checkout -b conflict-squash conflict-branch &&
 408        base=$(git rev-parse HEAD~4) &&
 409        set_fake_editor &&
 410        test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base &&
 411        echo three > conflict &&
 412        git add conflict &&
 413        FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
 414                git rebase --continue &&
 415        test $base = $(git rev-parse HEAD^) &&
 416        test 2 = $(git show | grep TWICE | wc -l) &&
 417        git checkout to-be-rebased &&
 418        git branch -D conflict-squash
 419'
 420
 421cat > expect-squash-fixup << EOF
 422B
 423
 424D
 425
 426ONCE
 427EOF
 428
 429test_expect_success 'squash and fixup generate correct log messages' '
 430        git checkout -b squash-fixup E &&
 431        base=$(git rev-parse HEAD~4) &&
 432        set_fake_editor &&
 433        FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
 434                EXPECT_HEADER_COUNT=4 \
 435                git rebase -i $base &&
 436        git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
 437        test_cmp expect-squash-fixup actual-squash-fixup &&
 438        git checkout to-be-rebased &&
 439        git branch -D squash-fixup
 440'
 441
 442test_expect_success 'squash ignores comments' '
 443        git checkout -b skip-comments E &&
 444        base=$(git rev-parse HEAD~4) &&
 445        set_fake_editor &&
 446        FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
 447                EXPECT_HEADER_COUNT=4 \
 448                git rebase -i $base &&
 449        test $base = $(git rev-parse HEAD^) &&
 450        test 1 = $(git show | grep ONCE | wc -l) &&
 451        git checkout to-be-rebased &&
 452        git branch -D skip-comments
 453'
 454
 455test_expect_success 'squash ignores blank lines' '
 456        git checkout -b skip-blank-lines E &&
 457        base=$(git rev-parse HEAD~4) &&
 458        set_fake_editor &&
 459        FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
 460                EXPECT_HEADER_COUNT=4 \
 461                git rebase -i $base &&
 462        test $base = $(git rev-parse HEAD^) &&
 463        test 1 = $(git show | grep ONCE | wc -l) &&
 464        git checkout to-be-rebased &&
 465        git branch -D skip-blank-lines
 466'
 467
 468test_expect_success 'squash works as expected' '
 469        git checkout -b squash-works no-conflict-branch &&
 470        one=$(git rev-parse HEAD~3) &&
 471        set_fake_editor &&
 472        FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
 473                git rebase -i HEAD~3 &&
 474        test $one = $(git rev-parse HEAD~2)
 475'
 476
 477test_expect_success 'interrupted squash works as expected' '
 478        git checkout -b interrupted-squash conflict-branch &&
 479        one=$(git rev-parse HEAD~3) &&
 480        set_fake_editor &&
 481        test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
 482        (echo one; echo two; echo four) > conflict &&
 483        git add conflict &&
 484        test_must_fail git rebase --continue &&
 485        echo resolved > conflict &&
 486        git add conflict &&
 487        git rebase --continue &&
 488        test $one = $(git rev-parse HEAD~2)
 489'
 490
 491test_expect_success 'interrupted squash works as expected (case 2)' '
 492        git checkout -b interrupted-squash2 conflict-branch &&
 493        one=$(git rev-parse HEAD~3) &&
 494        set_fake_editor &&
 495        test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
 496        (echo one; echo four) > conflict &&
 497        git add conflict &&
 498        test_must_fail git rebase --continue &&
 499        (echo one; echo two; echo four) > conflict &&
 500        git add conflict &&
 501        test_must_fail git rebase --continue &&
 502        echo resolved > conflict &&
 503        git add conflict &&
 504        git rebase --continue &&
 505        test $one = $(git rev-parse HEAD~2)
 506'
 507
 508test_expect_success '--continue tries to commit, even for "edit"' '
 509        echo unrelated > file7 &&
 510        git add file7 &&
 511        test_tick &&
 512        git commit -m "unrelated change" &&
 513        parent=$(git rev-parse HEAD^) &&
 514        test_tick &&
 515        set_fake_editor &&
 516        FAKE_LINES="edit 1" git rebase -i HEAD^ &&
 517        echo edited > file7 &&
 518        git add file7 &&
 519        FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
 520        test edited = $(git show HEAD:file7) &&
 521        git show HEAD | grep chouette &&
 522        test $parent = $(git rev-parse HEAD^)
 523'
 524
 525test_expect_success 'aborted --continue does not squash commits after "edit"' '
 526        old=$(git rev-parse HEAD) &&
 527        test_tick &&
 528        set_fake_editor &&
 529        FAKE_LINES="edit 1" git rebase -i HEAD^ &&
 530        echo "edited again" > file7 &&
 531        git add file7 &&
 532        test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue &&
 533        test $old = $(git rev-parse HEAD) &&
 534        git rebase --abort
 535'
 536
 537test_expect_success 'auto-amend only edited commits after "edit"' '
 538        test_tick &&
 539        set_fake_editor &&
 540        FAKE_LINES="edit 1" git rebase -i HEAD^ &&
 541        echo "edited again" > file7 &&
 542        git add file7 &&
 543        FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
 544        echo "and again" > file7 &&
 545        git add file7 &&
 546        test_tick &&
 547        test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue &&
 548        git rebase --abort
 549'
 550
 551test_expect_success 'clean error after failed "exec"' '
 552        test_tick &&
 553        test_when_finished "git rebase --abort || :" &&
 554        set_fake_editor &&
 555        test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ &&
 556        echo "edited again" > file7 &&
 557        git add file7 &&
 558        test_must_fail git rebase --continue 2>error &&
 559        test_i18ngrep "You have staged changes in your working tree." error
 560'
 561
 562test_expect_success 'rebase a detached HEAD' '
 563        grandparent=$(git rev-parse HEAD~2) &&
 564        git checkout $(git rev-parse HEAD) &&
 565        test_tick &&
 566        set_fake_editor &&
 567        FAKE_LINES="2 1" git rebase -i HEAD~2 &&
 568        test $grandparent = $(git rev-parse HEAD~2)
 569'
 570
 571test_expect_success 'rebase a commit violating pre-commit' '
 572
 573        mkdir -p .git/hooks &&
 574        write_script .git/hooks/pre-commit <<-\EOF &&
 575        test -z "$(git diff --cached --check)"
 576        EOF
 577        echo "monde! " >> file1 &&
 578        test_tick &&
 579        test_must_fail git commit -m doesnt-verify file1 &&
 580        git commit -m doesnt-verify --no-verify file1 &&
 581        test_tick &&
 582        set_fake_editor &&
 583        FAKE_LINES=2 git rebase -i HEAD~2
 584
 585'
 586
 587test_expect_success 'rebase with a file named HEAD in worktree' '
 588
 589        rm -fr .git/hooks &&
 590        git reset --hard &&
 591        git checkout -b branch3 A &&
 592
 593        (
 594                GIT_AUTHOR_NAME="Squashed Away" &&
 595                export GIT_AUTHOR_NAME &&
 596                >HEAD &&
 597                git add HEAD &&
 598                git commit -m "Add head" &&
 599                >BODY &&
 600                git add BODY &&
 601                git commit -m "Add body"
 602        ) &&
 603
 604        set_fake_editor &&
 605        FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
 606        test "$(git show -s --pretty=format:%an)" = "Squashed Away"
 607
 608'
 609
 610test_expect_success 'do "noop" when there is nothing to cherry-pick' '
 611
 612        git checkout -b branch4 HEAD &&
 613        GIT_EDITOR=: git commit --amend \
 614                --author="Somebody else <somebody@else.com>" &&
 615        test $(git rev-parse branch3) != $(git rev-parse branch4) &&
 616        set_fake_editor &&
 617        git rebase -i branch3 &&
 618        test $(git rev-parse branch3) = $(git rev-parse branch4)
 619
 620'
 621
 622test_expect_success 'submodule rebase setup' '
 623        git checkout A &&
 624        mkdir sub &&
 625        (
 626                cd sub && git init && >elif &&
 627                git add elif && git commit -m "submodule initial"
 628        ) &&
 629        echo 1 >file1 &&
 630        git add file1 sub &&
 631        test_tick &&
 632        git commit -m "One" &&
 633        echo 2 >file1 &&
 634        test_tick &&
 635        git commit -a -m "Two" &&
 636        (
 637                cd sub && echo 3 >elif &&
 638                git commit -a -m "submodule second"
 639        ) &&
 640        test_tick &&
 641        set_fake_editor &&
 642        git commit -a -m "Three changes submodule"
 643'
 644
 645test_expect_success 'submodule rebase -i' '
 646        set_fake_editor &&
 647        FAKE_LINES="1 squash 2 3" git rebase -i A
 648'
 649
 650test_expect_success 'submodule conflict setup' '
 651        git tag submodule-base &&
 652        git checkout HEAD^ &&
 653        (
 654                cd sub && git checkout HEAD^ && echo 4 >elif &&
 655                git add elif && git commit -m "submodule conflict"
 656        ) &&
 657        git add sub &&
 658        test_tick &&
 659        git commit -m "Conflict in submodule" &&
 660        git tag submodule-topic
 661'
 662
 663test_expect_success 'rebase -i continue with only submodule staged' '
 664        set_fake_editor &&
 665        test_must_fail git rebase -i submodule-base &&
 666        git add sub &&
 667        git rebase --continue &&
 668        test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
 669'
 670
 671test_expect_success 'rebase -i continue with unstaged submodule' '
 672        git checkout submodule-topic &&
 673        git reset --hard &&
 674        set_fake_editor &&
 675        test_must_fail git rebase -i submodule-base &&
 676        git reset &&
 677        git rebase --continue &&
 678        test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
 679'
 680
 681test_expect_success 'avoid unnecessary reset' '
 682        git checkout master &&
 683        git reset --hard &&
 684        test-chmtime =123456789 file3 &&
 685        git update-index --refresh &&
 686        HEAD=$(git rev-parse HEAD) &&
 687        set_fake_editor &&
 688        git rebase -i HEAD~4 &&
 689        test $HEAD = $(git rev-parse HEAD) &&
 690        MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
 691        test 123456789 = $MTIME
 692'
 693
 694test_expect_success 'reword' '
 695        git checkout -b reword-branch master &&
 696        set_fake_editor &&
 697        FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
 698        git show HEAD | grep "E changed" &&
 699        test $(git rev-parse master) != $(git rev-parse HEAD) &&
 700        test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
 701        FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
 702        git show HEAD^ | grep "D changed" &&
 703        FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
 704        git show HEAD~3 | grep "B changed" &&
 705        FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
 706        git show HEAD~2 | grep "C changed"
 707'
 708
 709test_expect_success 'rebase -i can copy notes' '
 710        git config notes.rewrite.rebase true &&
 711        git config notes.rewriteRef "refs/notes/*" &&
 712        test_commit n1 &&
 713        test_commit n2 &&
 714        test_commit n3 &&
 715        git notes add -m"a note" n3 &&
 716        set_fake_editor &&
 717        git rebase -i --onto n1 n2 &&
 718        test "a note" = "$(git notes show HEAD)"
 719'
 720
 721cat >expect <<EOF
 722an earlier note
 723
 724a note
 725EOF
 726
 727test_expect_success 'rebase -i can copy notes over a fixup' '
 728        git reset --hard n3 &&
 729        git notes add -m"an earlier note" n2 &&
 730        set_fake_editor &&
 731        GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
 732        git notes show > output &&
 733        test_cmp expect output
 734'
 735
 736test_expect_success 'rebase while detaching HEAD' '
 737        git symbolic-ref HEAD &&
 738        grandparent=$(git rev-parse HEAD~2) &&
 739        test_tick &&
 740        set_fake_editor &&
 741        FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
 742        test $grandparent = $(git rev-parse HEAD~2) &&
 743        test_must_fail git symbolic-ref HEAD
 744'
 745
 746test_tick # Ensure that the rebased commits get a different timestamp.
 747test_expect_success 'always cherry-pick with --no-ff' '
 748        git checkout no-ff-branch &&
 749        git tag original-no-ff-branch &&
 750        set_fake_editor &&
 751        git rebase -i --no-ff A &&
 752        touch empty &&
 753        for p in 0 1 2
 754        do
 755                test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
 756                git diff HEAD~$p original-no-ff-branch~$p > out &&
 757                test_cmp empty out
 758        done &&
 759        test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
 760        git diff HEAD~3 original-no-ff-branch~3 > out &&
 761        test_cmp empty out
 762'
 763
 764test_expect_success 'set up commits with funny messages' '
 765        git checkout -b funny A &&
 766        echo >>file1 &&
 767        test_tick &&
 768        git commit -a -m "end with slash\\" &&
 769        echo >>file1 &&
 770        test_tick &&
 771        git commit -a -m "something (\000) that looks like octal" &&
 772        echo >>file1 &&
 773        test_tick &&
 774        git commit -a -m "something (\n) that looks like a newline" &&
 775        echo >>file1 &&
 776        test_tick &&
 777        git commit -a -m "another commit"
 778'
 779
 780test_expect_success 'rebase-i history with funny messages' '
 781        git rev-list A..funny >expect &&
 782        test_tick &&
 783        set_fake_editor &&
 784        FAKE_LINES="1 2 3 4" git rebase -i A &&
 785        git rev-list A.. >actual &&
 786        test_cmp expect actual
 787'
 788
 789test_expect_success 'prepare for rebase -i --exec' '
 790        git checkout master &&
 791        git checkout -b execute &&
 792        test_commit one_exec main.txt one_exec &&
 793        test_commit two_exec main.txt two_exec &&
 794        test_commit three_exec main.txt three_exec
 795'
 796
 797test_expect_success 'running "git rebase -i --exec git show HEAD"' '
 798        set_fake_editor &&
 799        git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
 800        (
 801                FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
 802                export FAKE_LINES &&
 803                git rebase -i HEAD~2 >expect
 804        ) &&
 805        sed -e "1,9d" expect >expected &&
 806        test_cmp expected actual
 807'
 808
 809test_expect_success 'running "git rebase --exec git show HEAD -i"' '
 810        git reset --hard execute &&
 811        set_fake_editor &&
 812        git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
 813        (
 814                FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
 815                export FAKE_LINES &&
 816                git rebase -i HEAD~2 >expect
 817        ) &&
 818        sed -e "1,9d" expect >expected &&
 819        test_cmp expected actual
 820'
 821
 822test_expect_success 'running "git rebase -ix git show HEAD"' '
 823        git reset --hard execute &&
 824        set_fake_editor &&
 825        git rebase -ix "git show HEAD" HEAD~2 >actual &&
 826        (
 827                FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
 828                export FAKE_LINES &&
 829                git rebase -i HEAD~2 >expect
 830        ) &&
 831        sed -e "1,9d" expect >expected &&
 832        test_cmp expected actual
 833'
 834
 835
 836test_expect_success 'rebase -ix with several <CMD>' '
 837        git reset --hard execute &&
 838        set_fake_editor &&
 839        git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
 840        (
 841                FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
 842                export FAKE_LINES &&
 843                git rebase -i HEAD~2 >expect
 844        ) &&
 845        sed -e "1,9d" expect >expected &&
 846        test_cmp expected actual
 847'
 848
 849test_expect_success 'rebase -ix with several instances of --exec' '
 850        git reset --hard execute &&
 851        set_fake_editor &&
 852        git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
 853        (
 854                FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
 855                                exec_git_show_HEAD exec_pwd" &&
 856                export FAKE_LINES &&
 857                git rebase -i HEAD~2 >expect
 858        ) &&
 859        sed -e "1,11d" expect >expected &&
 860        test_cmp expected actual
 861'
 862
 863test_expect_success 'rebase -ix with --autosquash' '
 864        git reset --hard execute &&
 865        git checkout -b autosquash &&
 866        echo second >second.txt &&
 867        git add second.txt &&
 868        git commit -m "fixup! two_exec" &&
 869        echo bis >bis.txt &&
 870        git add bis.txt &&
 871        git commit -m "fixup! two_exec" &&
 872        set_fake_editor &&
 873        (
 874                git checkout -b autosquash_actual &&
 875                git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
 876        ) &&
 877        git checkout autosquash &&
 878        (
 879                git checkout -b autosquash_expected &&
 880                FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
 881                export FAKE_LINES &&
 882                git rebase -i HEAD~4 >expect
 883        ) &&
 884        sed -e "1,13d" expect >expected &&
 885        test_cmp expected actual
 886'
 887
 888test_expect_success 'rebase --exec works without -i ' '
 889        git reset --hard execute &&
 890        rm -rf exec_output &&
 891        EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output"  HEAD~2 2>actual &&
 892        test_i18ngrep  "Successfully rebased and updated" actual &&
 893        test_line_count = 2 exec_output &&
 894        test_path_is_missing invoked_editor
 895'
 896
 897test_expect_success 'rebase -i --exec without <CMD>' '
 898        git reset --hard execute &&
 899        set_fake_editor &&
 900        test_must_fail git rebase -i --exec 2>tmp &&
 901        sed -e "1d" tmp >actual &&
 902        test_must_fail git rebase -h >expected &&
 903        test_cmp expected actual &&
 904        git checkout master
 905'
 906
 907test_expect_success 'rebase -i --root re-order and drop commits' '
 908        git checkout E &&
 909        set_fake_editor &&
 910        FAKE_LINES="3 1 2 5" git rebase -i --root &&
 911        test E = $(git cat-file commit HEAD | sed -ne \$p) &&
 912        test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
 913        test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
 914        test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
 915        test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
 916'
 917
 918test_expect_success 'rebase -i --root retain root commit author and message' '
 919        git checkout A &&
 920        echo B >file7 &&
 921        git add file7 &&
 922        GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
 923        set_fake_editor &&
 924        FAKE_LINES="2" git rebase -i --root &&
 925        git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
 926        git cat-file commit HEAD | grep -q "^different author$"
 927'
 928
 929test_expect_success 'rebase -i --root temporary sentinel commit' '
 930        git checkout B &&
 931        set_fake_editor &&
 932        test_must_fail env FAKE_LINES="2" git rebase -i --root &&
 933        git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
 934        git rebase --abort
 935'
 936
 937test_expect_success 'rebase -i --root fixup root commit' '
 938        git checkout B &&
 939        set_fake_editor &&
 940        FAKE_LINES="1 fixup 2" git rebase -i --root &&
 941        test A = $(git cat-file commit HEAD | sed -ne \$p) &&
 942        test B = $(git show HEAD:file1) &&
 943        test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
 944'
 945
 946test_expect_success 'rebase --edit-todo does not works on non-interactive rebase' '
 947        git reset --hard &&
 948        git checkout conflict-branch &&
 949        set_fake_editor &&
 950        test_must_fail git rebase --onto HEAD~2 HEAD~ &&
 951        test_must_fail git rebase --edit-todo &&
 952        git rebase --abort
 953'
 954
 955test_expect_success 'rebase --edit-todo can be used to modify todo' '
 956        git reset --hard &&
 957        git checkout no-conflict-branch^0 &&
 958        set_fake_editor &&
 959        FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
 960        FAKE_LINES="2 1" git rebase --edit-todo &&
 961        git rebase --continue &&
 962        test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
 963        test L = $(git cat-file commit HEAD | sed -ne \$p)
 964'
 965
 966test_expect_success 'rebase -i produces readable reflog' '
 967        git reset --hard &&
 968        git branch -f branch-reflog-test H &&
 969        set_fake_editor &&
 970        git rebase -i --onto I F branch-reflog-test &&
 971        cat >expect <<-\EOF &&
 972        rebase -i (finish): returning to refs/heads/branch-reflog-test
 973        rebase -i (pick): H
 974        rebase -i (pick): G
 975        rebase -i (start): checkout I
 976        EOF
 977        git reflog -n4 HEAD |
 978        sed "s/[^:]*: //" >actual &&
 979        test_cmp expect actual
 980'
 981
 982test_expect_success 'rebase -i respects core.commentchar' '
 983        git reset --hard &&
 984        git checkout E^0 &&
 985        test_config core.commentchar "\\" &&
 986        write_script remove-all-but-first.sh <<-\EOF &&
 987        sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
 988        mv "$1.tmp" "$1"
 989        EOF
 990        test_set_editor "$(pwd)/remove-all-but-first.sh" &&
 991        git rebase -i B &&
 992        test B = $(git cat-file commit HEAD^ | sed -ne \$p)
 993'
 994
 995test_expect_success 'rebase -i respects core.commentchar=auto' '
 996        test_config core.commentchar auto &&
 997        write_script copy-edit-script.sh <<-\EOF &&
 998        cp "$1" edit-script
 999        EOF
1000        test_set_editor "$(pwd)/copy-edit-script.sh" &&
1001        test_when_finished "git rebase --abort || :" &&
1002        git rebase -i HEAD^ &&
1003        test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1004'
1005
1006test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1007        test_when_finished "git branch -D torebase" &&
1008        git checkout -b torebase branch1 &&
1009        upstream=$(git rev-parse ":/J") &&
1010        onto=$(git rev-parse ":/A") &&
1011        git rebase --onto $onto $upstream &&
1012        git reset --hard branch1 &&
1013        git rebase --onto ":/A" ":/J" &&
1014        git checkout branch1
1015'
1016
1017test_expect_success 'rebase -i with --strategy and -X' '
1018        git checkout -b conflict-merge-use-theirs conflict-branch &&
1019        git reset --hard HEAD^ &&
1020        echo five >conflict &&
1021        echo Z >file1 &&
1022        git commit -a -m "one file conflict" &&
1023        EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1024        test $(git show conflict-branch:conflict) = $(cat conflict) &&
1025        test $(cat file1) = Z
1026'
1027
1028test_expect_success 'interrupted rebase -i with --strategy and -X' '
1029        git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1030        git reset --hard HEAD^ &&
1031        >breakpoint &&
1032        git add breakpoint &&
1033        git commit -m "breakpoint for interactive mode" &&
1034        echo five >conflict &&
1035        echo Z >file1 &&
1036        git commit -a -m "one file conflict" &&
1037        set_fake_editor &&
1038        FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive -Xours conflict-branch &&
1039        git rebase --continue &&
1040        test $(git show conflict-branch:conflict) = $(cat conflict) &&
1041        test $(cat file1) = Z
1042'
1043
1044test_expect_success 'rebase -i error on commits with \ in message' '
1045        current_head=$(git rev-parse HEAD) &&
1046        test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1047        test_commit TO-REMOVE will-conflict old-content &&
1048        test_commit "\temp" will-conflict new-content dummy &&
1049        test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1050        test_expect_code 1 grep  "      emp" error
1051'
1052
1053test_expect_success 'short SHA-1 setup' '
1054        test_when_finished "git checkout master" &&
1055        git checkout --orphan collide &&
1056        git rm -rf . &&
1057        (
1058        unset test_tick &&
1059        test_commit collide1 collide &&
1060        test_commit --notick collide2 collide &&
1061        test_commit --notick collide3 collide
1062        )
1063'
1064
1065test_expect_success 'short SHA-1 collide' '
1066        test_when_finished "reset_rebase && git checkout master" &&
1067        git checkout collide &&
1068        (
1069        unset test_tick &&
1070        test_tick &&
1071        set_fake_editor &&
1072        FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1073        FAKE_LINES="reword 1 2" git rebase -i HEAD~2
1074        )
1075'
1076
1077test_expect_success 'respect core.abbrev' '
1078        git config core.abbrev 12 &&
1079        set_cat_todo_editor &&
1080        test_must_fail git rebase -i HEAD~4 >todo-list &&
1081        test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1082'
1083
1084test_expect_success 'todo count' '
1085        write_script dump-raw.sh <<-\EOF &&
1086                cat "$1"
1087        EOF
1088        test_set_editor "$(pwd)/dump-raw.sh" &&
1089        git rebase -i HEAD~4 >actual &&
1090        test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1091'
1092
1093test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
1094        git checkout --force branch2 &&
1095        git clean -f &&
1096        set_fake_editor &&
1097        FAKE_LINES="edit 1 2" git rebase -i A &&
1098        test_cmp_rev HEAD F &&
1099        test_path_is_missing file6 &&
1100        >file6 &&
1101        test_must_fail git rebase --continue &&
1102        test_cmp_rev HEAD F &&
1103        rm file6 &&
1104        git rebase --continue &&
1105        test_cmp_rev HEAD I
1106'
1107
1108test_expect_success 'rebase -i commits that overwrite untracked files (squash)' '
1109        git checkout --force branch2 &&
1110        git clean -f &&
1111        git tag original-branch2 &&
1112        set_fake_editor &&
1113        FAKE_LINES="edit 1 squash 2" git rebase -i A &&
1114        test_cmp_rev HEAD F &&
1115        test_path_is_missing file6 &&
1116        >file6 &&
1117        test_must_fail git rebase --continue &&
1118        test_cmp_rev HEAD F &&
1119        rm file6 &&
1120        git rebase --continue &&
1121        test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1122        git reset --hard original-branch2
1123'
1124
1125test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
1126        git checkout --force branch2 &&
1127        git clean -f &&
1128        set_fake_editor &&
1129        FAKE_LINES="edit 1 2" git rebase -i --no-ff A &&
1130        test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1131        test_path_is_missing file6 &&
1132        >file6 &&
1133        test_must_fail git rebase --continue &&
1134        test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1135        rm file6 &&
1136        git rebase --continue &&
1137        test $(git cat-file commit HEAD | sed -ne \$p) = I
1138'
1139
1140test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
1141        git checkout -b commit-to-skip &&
1142        for double in X 3 1
1143        do
1144                test_seq 5 | sed "s/$double/&&/" >seq &&
1145                git add seq &&
1146                test_tick &&
1147                git commit -m seq-$double
1148        done &&
1149        git tag seq-onto &&
1150        git reset --hard HEAD~2 &&
1151        git cherry-pick seq-onto &&
1152        set_fake_editor &&
1153        test_must_fail env FAKE_LINES= git rebase -i seq-onto &&
1154        test -d .git/rebase-merge &&
1155        git rebase --continue &&
1156        git diff --exit-code seq-onto &&
1157        test ! -d .git/rebase-merge &&
1158        test ! -f .git/CHERRY_PICK_HEAD
1159'
1160
1161rebase_setup_and_clean () {
1162        test_when_finished "
1163                git checkout master &&
1164                test_might_fail git branch -D $1 &&
1165                test_might_fail git rebase --abort
1166        " &&
1167        git checkout -b $1 master
1168}
1169
1170test_expect_success 'drop' '
1171        rebase_setup_and_clean drop-test &&
1172        set_fake_editor &&
1173        FAKE_LINES="1 drop 2 3 drop 4 5" git rebase -i --root &&
1174        test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1175        test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1176        test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1177'
1178
1179cat >expect <<EOF
1180Successfully rebased and updated refs/heads/missing-commit.
1181EOF
1182
1183test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
1184        test_config rebase.missingCommitsCheck ignore &&
1185        rebase_setup_and_clean missing-commit &&
1186        set_fake_editor &&
1187        FAKE_LINES="1 2 3 4" \
1188                git rebase -i --root 2>actual &&
1189        test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1190        test_i18ncmp expect actual
1191'
1192
1193cat >expect <<EOF
1194Warning: some commits may have been dropped accidentally.
1195Dropped commits (newer to older):
1196 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1197To avoid this message, use "drop" to explicitly remove a commit.
1198
1199Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1200The possible behaviours are: ignore, warn, error.
1201
1202Successfully rebased and updated refs/heads/missing-commit.
1203EOF
1204
1205test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
1206        test_config rebase.missingCommitsCheck warn &&
1207        rebase_setup_and_clean missing-commit &&
1208        set_fake_editor &&
1209        FAKE_LINES="1 2 3 4" \
1210                git rebase -i --root 2>actual &&
1211        test_i18ncmp expect actual &&
1212        test D = $(git cat-file commit HEAD | sed -ne \$p)
1213'
1214
1215cat >expect <<EOF
1216Warning: some commits may have been dropped accidentally.
1217Dropped commits (newer to older):
1218 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1219 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2)
1220To avoid this message, use "drop" to explicitly remove a commit.
1221
1222Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1223The possible behaviours are: ignore, warn, error.
1224
1225You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1226Or you can abort the rebase with 'git rebase --abort'.
1227EOF
1228
1229test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
1230        test_config rebase.missingCommitsCheck error &&
1231        rebase_setup_and_clean missing-commit &&
1232        set_fake_editor &&
1233        test_must_fail env FAKE_LINES="1 2 4" \
1234                git rebase -i --root 2>actual &&
1235        test_i18ncmp expect actual &&
1236        cp .git/rebase-merge/git-rebase-todo.backup \
1237                .git/rebase-merge/git-rebase-todo &&
1238        FAKE_LINES="1 2 drop 3 4 drop 5" \
1239                git rebase --edit-todo &&
1240        git rebase --continue &&
1241        test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1242        test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1243'
1244
1245cat >expect <<EOF
1246Warning: the command isn't recognized in the following line:
1247 - badcmd $(git rev-list --oneline -1 master~1)
1248
1249You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1250Or you can abort the rebase with 'git rebase --abort'.
1251EOF
1252
1253test_expect_success 'static check of bad command' '
1254        rebase_setup_and_clean bad-cmd &&
1255        set_fake_editor &&
1256        test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1257                git rebase -i --root 2>actual &&
1258        test_i18ncmp expect actual &&
1259        FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
1260        git rebase --continue &&
1261        test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1262        test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1263'
1264
1265test_expect_success 'tabs and spaces are accepted in the todolist' '
1266        rebase_setup_and_clean indented-comment &&
1267        write_script add-indent.sh <<-\EOF &&
1268        (
1269                # Turn single spaces into space/tab mix
1270                sed "1s/ /      /g; 2s/ /  /g; 3s/ /    /g" "$1"
1271                printf "\n\t# comment\n #more\n\t # comment\n"
1272        ) >"$1.new"
1273        mv "$1.new" "$1"
1274        EOF
1275        test_set_editor "$(pwd)/add-indent.sh" &&
1276        git rebase -i HEAD^^^ &&
1277        test E = $(git cat-file commit HEAD | sed -ne \$p)
1278'
1279
1280cat >expect <<EOF
1281Warning: the SHA-1 is missing or isn't a commit in the following line:
1282 - edit XXXXXXX False commit
1283
1284You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1285Or you can abort the rebase with 'git rebase --abort'.
1286EOF
1287
1288test_expect_success 'static check of bad SHA-1' '
1289        rebase_setup_and_clean bad-sha &&
1290        set_fake_editor &&
1291        test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1292                git rebase -i --root 2>actual &&
1293        test_i18ncmp expect actual &&
1294        FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
1295        git rebase --continue &&
1296        test E = $(git cat-file commit HEAD | sed -ne \$p)
1297'
1298
1299test_expect_success 'editor saves as CR/LF' '
1300        git checkout -b with-crlf &&
1301        write_script add-crs.sh <<-\EOF &&
1302        sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1303        mv -f "$1".new "$1"
1304        EOF
1305        (
1306                test_set_editor "$(pwd)/add-crs.sh" &&
1307                git rebase -i HEAD^
1308        )
1309'
1310
1311SQ="'"
1312test_expect_success 'rebase -i --gpg-sign=<key-id>' '
1313        set_fake_editor &&
1314        FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
1315                >out 2>err &&
1316        test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1317'
1318
1319test_done