]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t3404-rebase-interactive.sh
t5703: replace "grep -a" usage by perl
[thirdparty/git.git] / t / t3404-rebase-interactive.sh
index b90ea0fe440ffff8ae876ce293b10c32262d9ad9..c5ce3ab760eae5b438dddf20fc1389824f21c7e3 100755 (executable)
@@ -72,15 +72,16 @@ test_expect_success 'rebase --keep-empty' '
        test_line_count = 6 actual
 '
 
-test_expect_success 'rebase -i with empty HEAD' '
+test_expect_success 'rebase -i with empty todo list' '
        cat >expect <<-\EOF &&
        error: nothing to do
        EOF
        (
                set_fake_editor &&
-               test_must_fail env FAKE_LINES="1 exec_true" \
-                       git rebase -i HEAD^ >actual 2>&1
+               test_must_fail env FAKE_LINES="#" \
+                       git rebase -i HEAD^ >output 2>&1
        ) &&
+       tail -n 1 output >actual &&  # Ignore output about changing todo list
        test_i18ncmp expect actual
 '
 
@@ -222,7 +223,7 @@ test_expect_success 'reflog for the branch shows state before rebase' '
 '
 
 test_expect_success 'reflog for the branch shows correct finish message' '
-       printf "rebase -i (finish): refs/heads/branch1 onto %s\n" \
+       printf "rebase (finish): refs/heads/branch1 onto %s\n" \
                "$(git rev-parse branch2)" >expected &&
        git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
        test_cmp expected actual
@@ -1137,7 +1138,7 @@ test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-int
        git checkout conflict-branch &&
        (
                set_fake_editor &&
-               test_must_fail git rebase -f --onto HEAD~2 HEAD~ &&
+               test_must_fail git rebase -f --apply --onto HEAD~2 HEAD~ &&
                test_must_fail git rebase --edit-todo
        ) &&
        git rebase --abort
@@ -1161,10 +1162,10 @@ test_expect_success 'rebase -i produces readable reflog' '
        git branch -f branch-reflog-test H &&
        git rebase -i --onto I F branch-reflog-test &&
        cat >expect <<-\EOF &&
-       rebase -i (finish): returning to refs/heads/branch-reflog-test
-       rebase -i (pick): H
-       rebase -i (pick): G
-       rebase -i (start): checkout I
+       rebase (finish): returning to refs/heads/branch-reflog-test
+       rebase (pick): H
+       rebase (pick): G
+       rebase (start): checkout I
        EOF
        git reflog -n4 HEAD |
        sed "s/[^:]*: //" >actual &&
@@ -1463,6 +1464,127 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
        test B = $(git cat-file commit HEAD^ | sed -ne \$p)
 '
 
+test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ignore' '
+       test_config rebase.missingCommitsCheck ignore &&
+       rebase_setup_and_clean missing-commit &&
+       (
+               set_fake_editor &&
+               FAKE_LINES="break 1 2 3 4 5" git rebase -i --root &&
+               FAKE_LINES="1 2 3 4" git rebase --edit-todo &&
+               git rebase --continue 2>actual
+       ) &&
+       test D = $(git cat-file commit HEAD | sed -ne \$p) &&
+       test_i18ngrep \
+               "Successfully rebased and updated refs/heads/missing-commit" \
+               actual
+'
+
+test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' '
+       cat >expect <<-EOF &&
+       error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4)
+       Warning: some commits may have been dropped accidentally.
+       Dropped commits (newer to older):
+        - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
+        - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4)
+       To avoid this message, use "drop" to explicitly remove a commit.
+       EOF
+       head -n4 expect >expect.2 &&
+       tail -n1 expect >>expect.2 &&
+       tail -n4 expect.2 >expect.3 &&
+       test_config rebase.missingCommitsCheck warn &&
+       rebase_setup_and_clean missing-commit &&
+       (
+               set_fake_editor &&
+               test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \
+                       git rebase -i --root &&
+               cp .git/rebase-merge/git-rebase-todo.backup orig &&
+               FAKE_LINES="2 3 4" git rebase --edit-todo 2>actual.2 &&
+               head -n6 actual.2 >actual &&
+               test_i18ncmp expect actual &&
+               cp orig .git/rebase-merge/git-rebase-todo &&
+               FAKE_LINES="1 2 3 4" git rebase --edit-todo 2>actual.2 &&
+               head -n4 actual.2 >actual &&
+               test_i18ncmp expect.3 actual &&
+               git rebase --continue 2>actual
+       ) &&
+       test D = $(git cat-file commit HEAD | sed -ne \$p) &&
+       test_i18ngrep \
+               "Successfully rebased and updated refs/heads/missing-commit" \
+               actual
+'
+
+test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' '
+       cat >expect <<-EOF &&
+       error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4)
+       Warning: some commits may have been dropped accidentally.
+       Dropped commits (newer to older):
+        - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
+        - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4)
+       To avoid this message, use "drop" to explicitly remove a commit.
+
+       Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
+       The possible behaviours are: ignore, warn, error.
+
+       You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''.
+       Or you can abort the rebase with '\''git rebase --abort'\''.
+       EOF
+       tail -n11 expect >expect.2 &&
+       head -n3 expect.2 >expect.3 &&
+       tail -n7 expect.2 >>expect.3 &&
+       test_config rebase.missingCommitsCheck error &&
+       rebase_setup_and_clean missing-commit &&
+       (
+               set_fake_editor &&
+               test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \
+                       git rebase -i --root &&
+               cp .git/rebase-merge/git-rebase-todo.backup orig &&
+               test_must_fail env FAKE_LINES="2 3 4" \
+                       git rebase --edit-todo 2>actual &&
+               test_i18ncmp expect actual &&
+               test_must_fail git rebase --continue 2>actual &&
+               test_i18ncmp expect.2 actual &&
+               test_must_fail git rebase --edit-todo &&
+               cp orig .git/rebase-merge/git-rebase-todo &&
+               test_must_fail env FAKE_LINES="1 2 3 4" \
+                       git rebase --edit-todo 2>actual &&
+               test_i18ncmp expect.3 actual &&
+               test_must_fail git rebase --continue 2>actual &&
+               test_i18ncmp expect.3 actual &&
+               cp orig .git/rebase-merge/git-rebase-todo &&
+               FAKE_LINES="1 2 3 4 drop 5" git rebase --edit-todo &&
+               git rebase --continue 2>actual
+       ) &&
+       test D = $(git cat-file commit HEAD | sed -ne \$p) &&
+       test_i18ngrep \
+               "Successfully rebased and updated refs/heads/missing-commit" \
+               actual
+'
+
+test_expect_success 'rebase.missingCommitsCheck = error after resolving conflicts' '
+       test_config rebase.missingCommitsCheck error &&
+       (
+               set_fake_editor &&
+               FAKE_LINES="drop 1 break 2 3 4" git rebase -i A E
+       ) &&
+       git rebase --edit-todo &&
+       test_must_fail git rebase --continue &&
+       echo x >file1 &&
+       git add file1 &&
+       git rebase --continue
+'
+
+test_expect_success 'rebase.missingCommitsCheck = error when editing for a second time' '
+       test_config rebase.missingCommitsCheck error &&
+       (
+               set_fake_editor &&
+               FAKE_LINES="1 break 2 3" git rebase -i A D &&
+               cp .git/rebase-merge/git-rebase-todo todo &&
+               test_must_fail env FAKE_LINES=2 git rebase --edit-todo &&
+               GIT_SEQUENCE_EDITOR="cp todo" git rebase --edit-todo &&
+               git rebase --continue
+       )
+'
+
 test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
        rebase_setup_and_clean abbrevcmd &&
        test_commit "first" file1.txt "first line" first &&