]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t3404-rebase-interactive.sh
Merge branch 'ec/fetch-mark-common-refs-trace2'
[thirdparty/git.git] / t / t3404-rebase-interactive.sh
index cb9b210000a6bdc09c0f6875639dd94dd580d457..bf0dc756d2e6ab5b8626c04d76f21d03fb712b28 100755 (executable)
@@ -29,9 +29,6 @@ Initial setup:
 
 . "$TEST_DIRECTORY"/lib-rebase.sh
 
-# WARNING: Modifications to the initial repository can change the SHA ID used
-# in the expect2 file for the 'stop on conflicting pick' test.
-
 test_expect_success 'setup' '
        test_commit A file1 &&
        test_commit B file1 &&
@@ -161,8 +158,6 @@ test_expect_success 'rebase -x with empty command fails' '
        test_i18ncmp expected actual
 '
 
-LF='
-'
 test_expect_success 'rebase -x with newline in command fails' '
        test_when_finished "git rebase --abort ||:" &&
        test_must_fail env git rebase -x "a${LF}b" @ 2>actual &&
@@ -189,7 +184,6 @@ test_expect_success 'implicit interactive rebase does not invoke sequence editor
 
 test_expect_success 'no changes are a nop' '
        git checkout branch2 &&
-       set_fake_editor &&
        git rebase -i F &&
        test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
        test $(git rev-parse I) = $(git rev-parse HEAD)
@@ -199,7 +193,6 @@ test_expect_success 'test the [branch] option' '
        git checkout -b dead-end &&
        git rm file6 &&
        git commit -m "stop here" &&
-       set_fake_editor &&
        git rebase -i F branch2 &&
        test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
        test $(git rev-parse I) = $(git rev-parse branch2) &&
@@ -208,7 +201,6 @@ test_expect_success 'test the [branch] option' '
 
 test_expect_success 'test --onto <branch>' '
        git checkout -b test-onto branch2 &&
-       set_fake_editor &&
        git rebase -i --onto branch1 F &&
        test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
        test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
@@ -218,7 +210,6 @@ test_expect_success 'test --onto <branch>' '
 test_expect_success 'rebase on top of a non-conflicting commit' '
        git checkout branch1 &&
        git tag original-branch1 &&
-       set_fake_editor &&
        git rebase -i branch2 &&
        test file6 = $(git diff --name-only original-branch1) &&
        test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
@@ -243,28 +234,30 @@ test_expect_success 'exchange two commits' '
                FAKE_LINES="2 1" git rebase -i HEAD~2
        ) &&
        test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
-       test G = $(git cat-file commit HEAD | sed -ne \$p)
+       test G = $(git cat-file commit HEAD | sed -ne \$p) &&
+       blob1=$(git rev-parse --short HEAD^:file1) &&
+       blob2=$(git rev-parse --short HEAD:file1) &&
+       commit=$(git rev-parse --short HEAD)
 '
 
 test_expect_success 'stop on conflicting pick' '
-       cat >expect <<-\EOF &&
+       cat >expect <<-EOF &&
        diff --git a/file1 b/file1
-       index f70f10e..fd79235 100644
+       index $blob1..$blob2 100644
        --- a/file1
        +++ b/file1
        @@ -1 +1 @@
        -A
        +G
        EOF
-       cat >expect2 <<-\EOF &&
+       cat >expect2 <<-EOF &&
        <<<<<<< HEAD
        D
        =======
        G
-       >>>>>>> 5d18e54... G
+       >>>>>>> $commit... G
        EOF
        git tag new-branch1 &&
-       set_fake_editor &&
        test_must_fail git rebase -i master &&
        test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
        test_cmp expect .git/rebase-merge/patch &&
@@ -293,7 +286,6 @@ test_expect_success 'abort' '
 test_expect_success 'abort with error when new base cannot be checked out' '
        git rm --cached file1 &&
        git commit -m "remove file in base" &&
-       set_fake_editor &&
        test_must_fail git rebase -i master > output 2>&1 &&
        test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
                output &&
@@ -308,7 +300,6 @@ test_expect_success 'retain authorship' '
        test_tick &&
        GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
        git tag twerp &&
-       set_fake_editor &&
        git rebase -i --onto master HEAD^ &&
        git show HEAD | grep "^Author: Twerp Snog"
 '
@@ -326,7 +317,6 @@ test_expect_success 'retain authorship w/ conflicts' '
        test_commit b conflict b conflict-b &&
        GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME &&
 
-       set_fake_editor &&
        test_must_fail git rebase -i conflict-a &&
        echo resolved >conflict &&
        git add conflict &&
@@ -357,7 +347,6 @@ test_expect_success 'retain authorship when squashing' '
 
 test_expect_success REBASE_P '-p handles "no changes" gracefully' '
        HEAD=$(git rev-parse HEAD) &&
-       set_fake_editor &&
        git rebase -i -p HEAD^ &&
        git update-index --refresh &&
        git diff-files --quiet &&
@@ -404,7 +393,6 @@ test_expect_success REBASE_P 'preserve merges with -p' '
        git commit -m M file1 &&
        git checkout -b to-be-rebased &&
        test_tick &&
-       set_fake_editor &&
        git rebase -i -p --onto branch1 master &&
        git update-index --refresh &&
        git diff-files --quiet &&
@@ -450,7 +438,6 @@ test_expect_success '--continue tries to commit' '
 test_expect_success 'verbose flag is heeded, even after --continue' '
        git reset --hard master@{1} &&
        test_tick &&
-       set_fake_editor &&
        test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
        echo resolved > file1 &&
        git add file1 &&
@@ -750,7 +737,6 @@ test_expect_success 'do "noop" when there is nothing to cherry-pick' '
        GIT_EDITOR=: git commit --amend \
                --author="Somebody else <somebody@else.com>" &&
        test $(git rev-parse branch3) != $(git rev-parse branch4) &&
-       set_fake_editor &&
        git rebase -i branch3 &&
        test $(git rev-parse branch3) = $(git rev-parse branch4)
 
@@ -775,7 +761,6 @@ test_expect_success 'submodule rebase setup' '
                git commit -a -m "submodule second"
        ) &&
        test_tick &&
-       set_fake_editor &&
        git commit -a -m "Three changes submodule"
 '
 
@@ -800,7 +785,6 @@ test_expect_success 'submodule conflict setup' '
 '
 
 test_expect_success 'rebase -i continue with only submodule staged' '
-       set_fake_editor &&
        test_must_fail git rebase -i submodule-base &&
        git add sub &&
        git rebase --continue &&
@@ -810,7 +794,6 @@ test_expect_success 'rebase -i continue with only submodule staged' '
 test_expect_success 'rebase -i continue with unstaged submodule' '
        git checkout submodule-topic &&
        git reset --hard &&
-       set_fake_editor &&
        test_must_fail git rebase -i submodule-base &&
        git reset &&
        git rebase --continue &&
@@ -823,7 +806,6 @@ test_expect_success 'avoid unnecessary reset' '
        test-tool chmtime =123456789 file3 &&
        git update-index --refresh &&
        HEAD=$(git rev-parse HEAD) &&
-       set_fake_editor &&
        git rebase -i HEAD~4 &&
        test $HEAD = $(git rev-parse HEAD) &&
        MTIME=$(test-tool chmtime --get file3) &&
@@ -858,7 +840,6 @@ test_expect_success 'rebase -i can copy notes' '
        test_commit n2 &&
        test_commit n3 &&
        git notes add -m"a note" n3 &&
-       set_fake_editor &&
        git rebase -i --onto n1 n2 &&
        test "a note" = "$(git notes show HEAD)"
 '
@@ -896,7 +877,6 @@ test_tick # Ensure that the rebased commits get a different timestamp.
 test_expect_success 'always cherry-pick with --no-ff' '
        git checkout no-ff-branch &&
        git tag original-no-ff-branch &&
-       set_fake_editor &&
        git rebase -i --no-ff A &&
        for p in 0 1 2
        do
@@ -1044,7 +1024,6 @@ test_expect_success 'rebase --exec works without -i ' '
 
 test_expect_success 'rebase -i --exec without <CMD>' '
        git reset --hard execute &&
-       set_fake_editor &&
        test_must_fail git rebase -i --exec 2>actual &&
        test_i18ngrep "requires a value" actual &&
        git checkout master
@@ -1082,7 +1061,7 @@ test_expect_success 'rebase -i --root temporary sentinel commit' '
                set_fake_editor &&
                test_must_fail env FAKE_LINES="2" git rebase -i --root
        ) &&
-       git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
+       git cat-file commit HEAD | grep "^tree $EMPTY_TREE" &&
        git rebase --abort
 '
 
@@ -1158,7 +1137,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 --onto HEAD~2 HEAD~ &&
+               test_must_fail git rebase -f --onto HEAD~2 HEAD~ &&
                test_must_fail git rebase --edit-todo
        ) &&
        git rebase --abort
@@ -1180,7 +1159,6 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' '
 test_expect_success 'rebase -i produces readable reflog' '
        git reset --hard &&
        git branch -f branch-reflog-test H &&
-       set_fake_editor &&
        git rebase -i --onto I F branch-reflog-test &&
        cat >expect <<-\EOF &&
        rebase -i (finish): returning to refs/heads/branch-reflog-test
@@ -1271,7 +1249,7 @@ test_expect_success 'rebase -i error on commits with \ in message' '
        test_expect_code 1 grep  "      emp" error
 '
 
-test_expect_success 'short SHA-1 setup' '
+test_expect_success SHA1 'short SHA-1 setup' '
        test_when_finished "git checkout master" &&
        git checkout --orphan collide &&
        git rm -rf . &&
@@ -1283,7 +1261,7 @@ test_expect_success 'short SHA-1 setup' '
        )
 '
 
-test_expect_success 'short SHA-1 collide' '
+test_expect_success SHA1 'short SHA-1 collide' '
        test_when_finished "reset_rebase && git checkout master" &&
        git checkout collide &&
        (
@@ -1557,7 +1535,6 @@ test_expect_success 'editor saves as CR/LF' '
        )
 '
 
-SQ="'"
 test_expect_success 'rebase -i --gpg-sign=<key-id>' '
        test_when_finished "test_might_fail git rebase --abort" &&
        (
@@ -1603,4 +1580,28 @@ test_expect_success 'valid author header when author contains single quote' '
        test_cmp expected actual
 '
 
+test_expect_success 'post-commit hook is called' '
+       test_when_finished "rm -f .git/hooks/post-commit" &&
+       >actual &&
+       mkdir -p .git/hooks &&
+       write_script .git/hooks/post-commit <<-\EOS &&
+       git rev-parse HEAD >>actual
+       EOS
+       (
+               set_fake_editor &&
+               FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
+               echo x>file3 &&
+               git add file3 &&
+               FAKE_COMMIT_MESSAGE=edited git rebase --continue
+       ) &&
+       git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \
+               >expect &&
+       test_cmp expect actual
+'
+
+# This must be the last test in this file
+test_expect_success '$EDITOR and friends are unchanged' '
+       test_editor_unchanged
+'
+
 test_done