Skip to content

Commit 60a8a6b

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d7ef036 commit 60a8a6b

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

t/t5402-post-merge-hook.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ test_expect_success setup '
2525
GIT_DIR=clone2/.git git update-index --add a
2626
'
2727

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+
'
3537

3638
test_expect_success 'post-merge does not run for up-to-date ' '
3739
GIT_DIR=clone1/.git git merge $commit0 &&

t/t5601-clone.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,10 @@ test_expect_success 'clone from hooks' '
7979
cd .. &&
8080
git init r1 &&
8181
cd r1 &&
82-
cat >.git/hooks/pre-commit <<-\EOF &&
83-
#!/bin/sh
82+
test_hook pre-commit <<-\EOF &&
8483
git clone ../r0 ../r2
8584
exit 1
8685
EOF
87-
chmod u+x .git/hooks/pre-commit &&
8886
: >file &&
8987
git add file &&
9088
test_must_fail git commit -m invoke-hook &&

0 commit comments

Comments
 (0)