tests: change "cat && chmod +x" to use "test_hook"

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>

Ævar Arnfjörð Bjarmason committed Mar 17, 2022 at 11:13 UTC 60a8a6bf6cf2cd7c8c0524c711df50dd5c2ace4f
2 files changed +10 -10
t/t5402-post-merge-hook.sh
+9 -7
@@ -25,13 +25,15 @@ test_expect_success setup '
25 GIT_DIR=clone2/.git git update-index --add a
26 '
27
28 -for clone in 1 2; do
29 - cat >clone${clone}/.git/hooks/post-merge <<'EOF'
30 -#!/bin/sh
31 -echo $@ >> $GIT_DIR/post-merge.args
32 -EOF
33 - chmod u+x clone${clone}/.git/hooks/post-merge
34 -done
28 +test_expect_success 'setup clone hooks' '
29 + test_when_finished "rm -f hook" &&
30 + cat >hook <<-\EOF &&
31 + echo $@ >>$GIT_DIR/post-merge.args
32 + EOF
33 +
34 + test_hook --setup -C clone1 post-merge <hook &&
35 + test_hook --setup -C clone2 post-merge <hook
36 +'
37
38 test_expect_success 'post-merge does not run for up-to-date ' '
39 GIT_DIR=clone1/.git git merge $commit0 &&
t/t5601-clone.sh
+1 -3
@@ -79,12 +79,10 @@ test_expect_success 'clone from hooks' '
79 cd .. &&
80 git init r1 &&
81 cd r1 &&
82 - cat >.git/hooks/pre-commit <<-\EOF &&
83 - #!/bin/sh
82 + test_hook pre-commit <<-\EOF &&
83 git clone ../r0 ../r2
84 exit 1
85 EOF
87 - chmod u+x .git/hooks/pre-commit &&
86 : >file &&
87 git add file &&
88 test_must_fail git commit -m invoke-hook &&