]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tests: change "cat && chmod +x" to use "test_hook"
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Thu, 17 Mar 2022 10:13:13 +0000 (11:13 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Mar 2022 15:40:26 +0000 (08:40 -0700)
Refactor various test code to use the "test_hook" helper. This change:

 - Fixes the long-standing issues with those tests using "#!/bin/sh"
   instead of "#!$SHELL_PATH". Using "#!/bin/sh" here happened to work
   because this code was so simple that it e.g. worked on Solaris
   /bin/sh.

 - Removes the "mkdir .git/hooks" invocation, as explained in a
   preceding commit we'll rely on the default templates to create that
   directory for us.

For the test in "t5402-post-merge-hook.sh" it's easier and more
correct to unroll the for-loop into a test_expect_success, so let's do
that.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5402-post-merge-hook.sh
t/t5601-clone.sh

index 3e5e19c719170112fa77f924c0b9a6828eea2f6c..915af2de95e162a9581ca23a6efb229737e665a6 100755 (executable)
@@ -25,13 +25,15 @@ test_expect_success setup '
        GIT_DIR=clone2/.git git update-index --add a
 '
 
-for clone in 1 2; do
-       cat >clone${clone}/.git/hooks/post-merge <<'EOF'
-#!/bin/sh
-echo $@ >> $GIT_DIR/post-merge.args
-EOF
-       chmod u+x clone${clone}/.git/hooks/post-merge
-done
+test_expect_success 'setup clone hooks' '
+       test_when_finished "rm -f hook" &&
+       cat >hook <<-\EOF &&
+       echo $@ >>$GIT_DIR/post-merge.args
+       EOF
+
+       test_hook --setup -C clone1 post-merge <hook &&
+       test_hook --setup -C clone2 post-merge <hook
+'
 
 test_expect_success 'post-merge does not run for up-to-date ' '
        GIT_DIR=clone1/.git git merge $commit0 &&
index 83c24fc97a7b1f067f1c04bf93ba849e9ffff945..4a61f2c901ea3da6a37d04caca1f799ad9135783 100755 (executable)
@@ -79,12 +79,10 @@ test_expect_success 'clone from hooks' '
        cd .. &&
        git init r1 &&
        cd r1 &&
-       cat >.git/hooks/pre-commit <<-\EOF &&
-       #!/bin/sh
+       test_hook pre-commit <<-\EOF &&
        git clone ../r0 ../r2
        exit 1
        EOF
-       chmod u+x .git/hooks/pre-commit &&
        : >file &&
        git add file &&
        test_must_fail git commit -m invoke-hook &&