]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tests: change "mkdir -p && write_script" to use "test_hook"
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Thu, 17 Mar 2022 10:13:14 +0000 (11:13 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Mar 2022 15:40:26 +0000 (08:40 -0700)
Change tests that used a "mkdir -p .git/hooks && write_script" pattern
to use the new "test_hook" helper instead. The new helper does not
create the .git/hooks directory, rather we assume that the default
template will do so for us.

An upcoming series[1] will extend "test_hook" to operate in a
"--template=" mode, but for now assuming that we have a .git/hooks
already is a safe assumption. If that assumption becomes false in the
future we'll only need to change 'test_hook", instead of all of these
callsites.

1. https://lore.kernel.org/git/cover-00.13-00000000000-20211212T201308Z-avarab@gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t0029-core-unsetenvvars.sh
t/t1350-config-hooks-path.sh
t/t3404-rebase-interactive.sh
t/t3430-rebase-merges.sh
t/t4150-am.sh
t/t5403-post-checkout-hook.sh
t/t5534-push-signed.sh
t/t7113-post-index-change-hook.sh
t/t9001-send-email.sh

index b138e1d9cbcd9c459e8e1ce3849a199cb177f57b..4e8e90dd9824b33bd4420423a447decea46e848e 100755 (executable)
@@ -12,8 +12,7 @@ then
 fi
 
 test_expect_success 'setup' '
-       mkdir -p "$TRASH_DIRECTORY/.git/hooks" &&
-       write_script "$TRASH_DIRECTORY/.git/hooks/pre-commit" <<-\EOF
+       test_hook --setup pre-commit <<-\EOF
        echo $HOBBES >&2
        EOF
 '
index fa9647a7c0b7e39f2afd494b127d3e7e1c70c52c..f6dc83e2aabf69ec51364ae9a5f6d5d50ce8db14 100755 (executable)
@@ -6,11 +6,11 @@ test_description='Test the core.hooksPath configuration variable'
 
 test_expect_success 'set up a pre-commit hook in core.hooksPath' '
        >actual &&
-       mkdir -p .git/custom-hooks .git/hooks &&
+       mkdir -p .git/custom-hooks &&
        write_script .git/custom-hooks/pre-commit <<-\EOF &&
        echo CUSTOM >>actual
        EOF
-       write_script .git/hooks/pre-commit <<-\EOF
+       test_hook --setup pre-commit <<-\EOF
        echo NORMAL >>actual
        EOF
 '
index a38f2da7691e870f8dfa90936c0107d7d080e0d1..f31afd4a54754a982e26b78271317ea61a3b9cda 100755 (executable)
@@ -619,9 +619,7 @@ test_expect_success 'rebase a detached HEAD' '
 '
 
 test_expect_success 'rebase a commit violating pre-commit' '
-
-       mkdir -p .git/hooks &&
-       write_script .git/hooks/pre-commit <<-\EOF &&
+       test_hook pre-commit <<-\EOF &&
        test -z "$(git diff --cached --check)"
        EOF
        echo "monde! " >> file1 &&
@@ -636,8 +634,6 @@ test_expect_success 'rebase a commit violating pre-commit' '
 '
 
 test_expect_success 'rebase with a file named HEAD in worktree' '
-
-       rm -fr .git/hooks &&
        git reset --hard &&
        git checkout -b branch3 A &&
 
@@ -1688,10 +1684,8 @@ test_expect_success 'valid author header when author contains single quote' '
 '
 
 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 &&
+       test_hook post-commit <<-\EOS &&
        git rev-parse HEAD >>actual
        EOS
        (
index 43c82d9a33b003d194e1ec7284e312e4e84337d7..f351701fec281aa6a88e9ee7185101639c8bbcd6 100755 (executable)
@@ -292,9 +292,9 @@ test_expect_success 'post-rewrite hook and fixups work for merges' '
        git commit --fixup HEAD same2.t &&
        fixup="$(git rev-parse HEAD)" &&
 
-       mkdir -p .git/hooks &&
-       test_when_finished "rm .git/hooks/post-rewrite" &&
-       echo "cat >actual" | write_script .git/hooks/post-rewrite &&
+       test_hook post-rewrite <<-\EOF &&
+       cat >actual
+       EOF
 
        test_tick &&
        git rebase -i --autosquash -r HEAD^^^ &&
index 159fae8d0162a3d1f0543d28a9817f156b45df5c..cdad4b688078adc24da922bce14e130982f4484e 100755 (executable)
@@ -315,12 +315,10 @@ test_expect_success 'am --patch-format=hg applies hg patch' '
 '
 
 test_expect_success 'am with applypatch-msg hook' '
-       test_when_finished "rm -f .git/hooks/applypatch-msg" &&
        rm -fr .git/rebase-apply &&
        git reset --hard &&
        git checkout first &&
-       mkdir -p .git/hooks &&
-       write_script .git/hooks/applypatch-msg <<-\EOF &&
+       test_hook applypatch-msg <<-\EOF &&
        cat "$1" >actual-msg &&
        echo hook-message >"$1"
        EOF
@@ -335,12 +333,10 @@ test_expect_success 'am with applypatch-msg hook' '
 '
 
 test_expect_success 'am with failing applypatch-msg hook' '
-       test_when_finished "rm -f .git/hooks/applypatch-msg" &&
        rm -fr .git/rebase-apply &&
        git reset --hard &&
        git checkout first &&
-       mkdir -p .git/hooks &&
-       write_script .git/hooks/applypatch-msg <<-\EOF &&
+       test_hook applypatch-msg <<-\EOF &&
        exit 1
        EOF
        test_must_fail git am patch1 &&
@@ -350,12 +346,10 @@ test_expect_success 'am with failing applypatch-msg hook' '
 '
 
 test_expect_success 'am with pre-applypatch hook' '
-       test_when_finished "rm -f .git/hooks/pre-applypatch" &&
        rm -fr .git/rebase-apply &&
        git reset --hard &&
        git checkout first &&
-       mkdir -p .git/hooks &&
-       write_script .git/hooks/pre-applypatch <<-\EOF &&
+       test_hook pre-applypatch <<-\EOF &&
        git diff first >diff.actual
        exit 0
        EOF
@@ -368,12 +362,10 @@ test_expect_success 'am with pre-applypatch hook' '
 '
 
 test_expect_success 'am with failing pre-applypatch hook' '
-       test_when_finished "rm -f .git/hooks/pre-applypatch" &&
        rm -fr .git/rebase-apply &&
        git reset --hard &&
        git checkout first &&
-       mkdir -p .git/hooks &&
-       write_script .git/hooks/pre-applypatch <<-\EOF &&
+       test_hook pre-applypatch <<-\EOF &&
        exit 1
        EOF
        test_must_fail git am patch1 &&
@@ -383,12 +375,10 @@ test_expect_success 'am with failing pre-applypatch hook' '
 '
 
 test_expect_success 'am with post-applypatch hook' '
-       test_when_finished "rm -f .git/hooks/post-applypatch" &&
        rm -fr .git/rebase-apply &&
        git reset --hard &&
        git checkout first &&
-       mkdir -p .git/hooks &&
-       write_script .git/hooks/post-applypatch <<-\EOF &&
+       test_hook post-applypatch <<-\EOF &&
        git rev-parse HEAD >head.actual
        git diff second >diff.actual
        exit 0
@@ -403,12 +393,10 @@ test_expect_success 'am with post-applypatch hook' '
 '
 
 test_expect_success 'am with failing post-applypatch hook' '
-       test_when_finished "rm -f .git/hooks/post-applypatch" &&
        rm -fr .git/rebase-apply &&
        git reset --hard &&
        git checkout first &&
-       mkdir -p .git/hooks &&
-       write_script .git/hooks/post-applypatch <<-\EOF &&
+       test_hook post-applypatch <<-\EOF &&
        git rev-parse HEAD >head.actual
        exit 1
        EOF
index d11818169067bb349c45cc42abb33826d99fe60c..978f240cdaceb4e7593adcf89136e9de9b558aa1 100755 (executable)
@@ -10,8 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . ./test-lib.sh
 
 test_expect_success setup '
-       mkdir -p .git/hooks &&
-       write_script .git/hooks/post-checkout <<-\EOF &&
+       test_hook --setup post-checkout <<-\EOF &&
        echo "$@" >.git/post-checkout.args
        EOF
        test_commit one &&
index 24d374adbae8846de060ae24db9f92b1e8e5e207..7c0a148e73c9e54003ed0fbad0805fe00f31eed0 100755 (executable)
@@ -35,8 +35,7 @@ test_expect_success setup '
 
 test_expect_success 'unsigned push does not send push certificate' '
        prepare_dst &&
-       mkdir -p dst/.git/hooks &&
-       write_script dst/.git/hooks/post-receive <<-\EOF &&
+       test_hook -C dst post-receive <<-\EOF &&
        # discard the update list
        cat >/dev/null
        # record the push certificate
@@ -52,8 +51,7 @@ test_expect_success 'unsigned push does not send push certificate' '
 
 test_expect_success 'talking with a receiver without push certificate support' '
        prepare_dst &&
-       mkdir -p dst/.git/hooks &&
-       write_script dst/.git/hooks/post-receive <<-\EOF &&
+       test_hook -C dst post-receive <<-\EOF &&
        # discard the update list
        cat >/dev/null
        # record the push certificate
@@ -69,22 +67,19 @@ test_expect_success 'talking with a receiver without push certificate support' '
 
 test_expect_success 'push --signed fails with a receiver without push certificate support' '
        prepare_dst &&
-       mkdir -p dst/.git/hooks &&
        test_must_fail git push --signed dst noop ff +noff 2>err &&
        test_i18ngrep "the receiving end does not support" err
 '
 
 test_expect_success 'push --signed=1 is accepted' '
        prepare_dst &&
-       mkdir -p dst/.git/hooks &&
        test_must_fail git push --signed=1 dst noop ff +noff 2>err &&
        test_i18ngrep "the receiving end does not support" err
 '
 
 test_expect_success GPG 'no certificate for a signed push with no update' '
        prepare_dst &&
-       mkdir -p dst/.git/hooks &&
-       write_script dst/.git/hooks/post-receive <<-\EOF &&
+       test_hook -C dst post-receive <<-\EOF &&
        if test -n "${GIT_PUSH_CERT-}"
        then
                git cat-file blob $GIT_PUSH_CERT >../push-cert
@@ -96,9 +91,8 @@ test_expect_success GPG 'no certificate for a signed push with no update' '
 
 test_expect_success GPG 'signed push sends push certificate' '
        prepare_dst &&
-       mkdir -p dst/.git/hooks &&
        git -C dst config receive.certnonceseed sekrit &&
-       write_script dst/.git/hooks/post-receive <<-\EOF &&
+       test_hook -C dst post-receive <<-\EOF &&
        # discard the update list
        cat >/dev/null
        # record the push certificate
@@ -139,10 +133,9 @@ test_expect_success GPG 'signed push sends push certificate' '
 
 test_expect_success GPGSSH 'ssh signed push sends push certificate' '
        prepare_dst &&
-       mkdir -p dst/.git/hooks &&
        git -C dst config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
        git -C dst config receive.certnonceseed sekrit &&
-       write_script dst/.git/hooks/post-receive <<-\EOF &&
+       test_hook -C dst post-receive <<-\EOF &&
        # discard the update list
        cat >/dev/null
        # record the push certificate
@@ -223,9 +216,8 @@ test_expect_success GPG 'inconsistent push options in signed push not allowed' '
 
 test_expect_success GPG 'fail without key and heed user.signingkey' '
        prepare_dst &&
-       mkdir -p dst/.git/hooks &&
        git -C dst config receive.certnonceseed sekrit &&
-       write_script dst/.git/hooks/post-receive <<-\EOF &&
+       test_hook -C dst post-receive <<-\EOF &&
        # discard the update list
        cat >/dev/null
        # record the push certificate
@@ -273,9 +265,8 @@ test_expect_success GPG 'fail without key and heed user.signingkey' '
 test_expect_success GPGSM 'fail without key and heed user.signingkey x509' '
        test_config gpg.format x509 &&
        prepare_dst &&
-       mkdir -p dst/.git/hooks &&
        git -C dst config receive.certnonceseed sekrit &&
-       write_script dst/.git/hooks/post-receive <<-\EOF &&
+       test_hook -C dst post-receive <<-\EOF &&
        # discard the update list
        cat >/dev/null
        # record the push certificate
@@ -326,10 +317,9 @@ test_expect_success GPGSM 'fail without key and heed user.signingkey x509' '
 test_expect_success GPGSSH 'fail without key and heed user.signingkey ssh' '
        test_config gpg.format ssh &&
        prepare_dst &&
-       mkdir -p dst/.git/hooks &&
        git -C dst config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
        git -C dst config receive.certnonceseed sekrit &&
-       write_script dst/.git/hooks/post-receive <<-\EOF &&
+       test_hook -C dst post-receive <<-\EOF &&
        # discard the update list
        cat >/dev/null
        # record the push certificate
index a21781d68a1abf91bf2d34d029a1c90732991f2b..58e55a7c7791616fa22efec12c79350c308fcaf9 100755 (executable)
@@ -17,8 +17,7 @@ test_expect_success 'setup' '
 '
 
 test_expect_success 'test status, add, commit, others trigger hook without flags set' '
-       mkdir -p .git/hooks &&
-       write_script .git/hooks/post-index-change <<-\EOF &&
+       test_hook post-index-change <<-\EOF &&
                if test "$1" -eq 1; then
                        echo "Invalid combination of flags passed to hook; updated_workdir is set." >testfailure
                        exit 1
@@ -63,7 +62,7 @@ test_expect_success 'test status, add, commit, others trigger hook without flags
 '
 
 test_expect_success 'test checkout and reset trigger the hook' '
-       write_script .git/hooks/post-index-change <<-\EOF &&
+       test_hook post-index-change <<-\EOF &&
                if test "$1" -eq 1 && test "$2" -eq 1; then
                        echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure
                        exit 1
@@ -106,7 +105,7 @@ test_expect_success 'test checkout and reset trigger the hook' '
 '
 
 test_expect_success 'test reset --mixed and update-index triggers the hook' '
-       write_script .git/hooks/post-index-change <<-\EOF &&
+       test_hook post-index-change <<-\EOF &&
                if test "$1" -eq 1 && test "$2" -eq 1; then
                        echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure
                        exit 1
index 84d0f40d76a979b1e98ca911979fd00d64c3f80e..42694fe58419fbf13e78f72dde91a0ac2f61e2cb 100755 (executable)
@@ -2288,9 +2288,7 @@ test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
 '
 
 test_expect_success $PREREQ 'invoke hook' '
-       mkdir -p .git/hooks &&
-
-       write_script .git/hooks/sendemail-validate <<-\EOF &&
+       test_hook sendemail-validate <<-\EOF &&
        # test that we have the correct environment variable, pwd, and
        # argument
        case "$GIT_DIR" in