Skip to content

Commit bef805b

Browse files
avargitster
authored andcommitted
tests: change "mkdir -p && write_script" to use "test_hook"
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/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 60a8a6b commit bef805b

9 files changed

+27
-60
lines changed

t/t0029-core-unsetenvvars.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ then
1212
fi
1313

1414
test_expect_success 'setup' '
15-
mkdir -p "$TRASH_DIRECTORY/.git/hooks" &&
16-
write_script "$TRASH_DIRECTORY/.git/hooks/pre-commit" <<-\EOF
15+
test_hook --setup pre-commit <<-\EOF
1716
echo $HOBBES >&2
1817
EOF
1918
'

t/t1350-config-hooks-path.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ test_description='Test the core.hooksPath configuration variable'
66

77
test_expect_success 'set up a pre-commit hook in core.hooksPath' '
88
>actual &&
9-
mkdir -p .git/custom-hooks .git/hooks &&
9+
mkdir -p .git/custom-hooks &&
1010
write_script .git/custom-hooks/pre-commit <<-\EOF &&
1111
echo CUSTOM >>actual
1212
EOF
13-
write_script .git/hooks/pre-commit <<-\EOF
13+
test_hook --setup pre-commit <<-\EOF
1414
echo NORMAL >>actual
1515
EOF
1616
'

t/t3404-rebase-interactive.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,7 @@ test_expect_success 'rebase a detached HEAD' '
619619
'
620620

621621
test_expect_success 'rebase a commit violating pre-commit' '
622-
623-
mkdir -p .git/hooks &&
624-
write_script .git/hooks/pre-commit <<-\EOF &&
622+
test_hook pre-commit <<-\EOF &&
625623
test -z "$(git diff --cached --check)"
626624
EOF
627625
echo "monde! " >> file1 &&
@@ -636,8 +634,6 @@ test_expect_success 'rebase a commit violating pre-commit' '
636634
'
637635

638636
test_expect_success 'rebase with a file named HEAD in worktree' '
639-
640-
rm -fr .git/hooks &&
641637
git reset --hard &&
642638
git checkout -b branch3 A &&
643639
@@ -1688,10 +1684,8 @@ test_expect_success 'valid author header when author contains single quote' '
16881684
'
16891685

16901686
test_expect_success 'post-commit hook is called' '
1691-
test_when_finished "rm -f .git/hooks/post-commit" &&
16921687
>actual &&
1693-
mkdir -p .git/hooks &&
1694-
write_script .git/hooks/post-commit <<-\EOS &&
1688+
test_hook post-commit <<-\EOS &&
16951689
git rev-parse HEAD >>actual
16961690
EOS
16971691
(

t/t3430-rebase-merges.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ test_expect_success 'post-rewrite hook and fixups work for merges' '
292292
git commit --fixup HEAD same2.t &&
293293
fixup="$(git rev-parse HEAD)" &&
294294
295-
mkdir -p .git/hooks &&
296-
test_when_finished "rm .git/hooks/post-rewrite" &&
297-
echo "cat >actual" | write_script .git/hooks/post-rewrite &&
295+
test_hook post-rewrite <<-\EOF &&
296+
cat >actual
297+
EOF
298298
299299
test_tick &&
300300
git rebase -i --autosquash -r HEAD^^^ &&

t/t4150-am.sh

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,10 @@ test_expect_success 'am --patch-format=hg applies hg patch' '
315315
'
316316

317317
test_expect_success 'am with applypatch-msg hook' '
318-
test_when_finished "rm -f .git/hooks/applypatch-msg" &&
319318
rm -fr .git/rebase-apply &&
320319
git reset --hard &&
321320
git checkout first &&
322-
mkdir -p .git/hooks &&
323-
write_script .git/hooks/applypatch-msg <<-\EOF &&
321+
test_hook applypatch-msg <<-\EOF &&
324322
cat "$1" >actual-msg &&
325323
echo hook-message >"$1"
326324
EOF
@@ -335,12 +333,10 @@ test_expect_success 'am with applypatch-msg hook' '
335333
'
336334

337335
test_expect_success 'am with failing applypatch-msg hook' '
338-
test_when_finished "rm -f .git/hooks/applypatch-msg" &&
339336
rm -fr .git/rebase-apply &&
340337
git reset --hard &&
341338
git checkout first &&
342-
mkdir -p .git/hooks &&
343-
write_script .git/hooks/applypatch-msg <<-\EOF &&
339+
test_hook applypatch-msg <<-\EOF &&
344340
exit 1
345341
EOF
346342
test_must_fail git am patch1 &&
@@ -350,12 +346,10 @@ test_expect_success 'am with failing applypatch-msg hook' '
350346
'
351347

352348
test_expect_success 'am with pre-applypatch hook' '
353-
test_when_finished "rm -f .git/hooks/pre-applypatch" &&
354349
rm -fr .git/rebase-apply &&
355350
git reset --hard &&
356351
git checkout first &&
357-
mkdir -p .git/hooks &&
358-
write_script .git/hooks/pre-applypatch <<-\EOF &&
352+
test_hook pre-applypatch <<-\EOF &&
359353
git diff first >diff.actual
360354
exit 0
361355
EOF
@@ -368,12 +362,10 @@ test_expect_success 'am with pre-applypatch hook' '
368362
'
369363

370364
test_expect_success 'am with failing pre-applypatch hook' '
371-
test_when_finished "rm -f .git/hooks/pre-applypatch" &&
372365
rm -fr .git/rebase-apply &&
373366
git reset --hard &&
374367
git checkout first &&
375-
mkdir -p .git/hooks &&
376-
write_script .git/hooks/pre-applypatch <<-\EOF &&
368+
test_hook pre-applypatch <<-\EOF &&
377369
exit 1
378370
EOF
379371
test_must_fail git am patch1 &&
@@ -383,12 +375,10 @@ test_expect_success 'am with failing pre-applypatch hook' '
383375
'
384376

385377
test_expect_success 'am with post-applypatch hook' '
386-
test_when_finished "rm -f .git/hooks/post-applypatch" &&
387378
rm -fr .git/rebase-apply &&
388379
git reset --hard &&
389380
git checkout first &&
390-
mkdir -p .git/hooks &&
391-
write_script .git/hooks/post-applypatch <<-\EOF &&
381+
test_hook post-applypatch <<-\EOF &&
392382
git rev-parse HEAD >head.actual
393383
git diff second >diff.actual
394384
exit 0
@@ -403,12 +393,10 @@ test_expect_success 'am with post-applypatch hook' '
403393
'
404394

405395
test_expect_success 'am with failing post-applypatch hook' '
406-
test_when_finished "rm -f .git/hooks/post-applypatch" &&
407396
rm -fr .git/rebase-apply &&
408397
git reset --hard &&
409398
git checkout first &&
410-
mkdir -p .git/hooks &&
411-
write_script .git/hooks/post-applypatch <<-\EOF &&
399+
test_hook post-applypatch <<-\EOF &&
412400
git rev-parse HEAD >head.actual
413401
exit 1
414402
EOF

t/t5403-post-checkout-hook.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1010
. ./test-lib.sh
1111

1212
test_expect_success setup '
13-
mkdir -p .git/hooks &&
14-
write_script .git/hooks/post-checkout <<-\EOF &&
13+
test_hook --setup post-checkout <<-\EOF &&
1514
echo "$@" >.git/post-checkout.args
1615
EOF
1716
test_commit one &&

t/t5534-push-signed.sh

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ test_expect_success setup '
3535

3636
test_expect_success 'unsigned push does not send push certificate' '
3737
prepare_dst &&
38-
mkdir -p dst/.git/hooks &&
39-
write_script dst/.git/hooks/post-receive <<-\EOF &&
38+
test_hook -C dst post-receive <<-\EOF &&
4039
# discard the update list
4140
cat >/dev/null
4241
# record the push certificate
@@ -52,8 +51,7 @@ test_expect_success 'unsigned push does not send push certificate' '
5251

5352
test_expect_success 'talking with a receiver without push certificate support' '
5453
prepare_dst &&
55-
mkdir -p dst/.git/hooks &&
56-
write_script dst/.git/hooks/post-receive <<-\EOF &&
54+
test_hook -C dst post-receive <<-\EOF &&
5755
# discard the update list
5856
cat >/dev/null
5957
# record the push certificate
@@ -69,22 +67,19 @@ test_expect_success 'talking with a receiver without push certificate support' '
6967

7068
test_expect_success 'push --signed fails with a receiver without push certificate support' '
7169
prepare_dst &&
72-
mkdir -p dst/.git/hooks &&
7370
test_must_fail git push --signed dst noop ff +noff 2>err &&
7471
test_i18ngrep "the receiving end does not support" err
7572
'
7673

7774
test_expect_success 'push --signed=1 is accepted' '
7875
prepare_dst &&
79-
mkdir -p dst/.git/hooks &&
8076
test_must_fail git push --signed=1 dst noop ff +noff 2>err &&
8177
test_i18ngrep "the receiving end does not support" err
8278
'
8379

8480
test_expect_success GPG 'no certificate for a signed push with no update' '
8581
prepare_dst &&
86-
mkdir -p dst/.git/hooks &&
87-
write_script dst/.git/hooks/post-receive <<-\EOF &&
82+
test_hook -C dst post-receive <<-\EOF &&
8883
if test -n "${GIT_PUSH_CERT-}"
8984
then
9085
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' '
9691

9792
test_expect_success GPG 'signed push sends push certificate' '
9893
prepare_dst &&
99-
mkdir -p dst/.git/hooks &&
10094
git -C dst config receive.certnonceseed sekrit &&
101-
write_script dst/.git/hooks/post-receive <<-\EOF &&
95+
test_hook -C dst post-receive <<-\EOF &&
10296
# discard the update list
10397
cat >/dev/null
10498
# record the push certificate
@@ -139,10 +133,9 @@ test_expect_success GPG 'signed push sends push certificate' '
139133

140134
test_expect_success GPGSSH 'ssh signed push sends push certificate' '
141135
prepare_dst &&
142-
mkdir -p dst/.git/hooks &&
143136
git -C dst config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
144137
git -C dst config receive.certnonceseed sekrit &&
145-
write_script dst/.git/hooks/post-receive <<-\EOF &&
138+
test_hook -C dst post-receive <<-\EOF &&
146139
# discard the update list
147140
cat >/dev/null
148141
# record the push certificate
@@ -223,9 +216,8 @@ test_expect_success GPG 'inconsistent push options in signed push not allowed' '
223216

224217
test_expect_success GPG 'fail without key and heed user.signingkey' '
225218
prepare_dst &&
226-
mkdir -p dst/.git/hooks &&
227219
git -C dst config receive.certnonceseed sekrit &&
228-
write_script dst/.git/hooks/post-receive <<-\EOF &&
220+
test_hook -C dst post-receive <<-\EOF &&
229221
# discard the update list
230222
cat >/dev/null
231223
# record the push certificate
@@ -273,9 +265,8 @@ test_expect_success GPG 'fail without key and heed user.signingkey' '
273265
test_expect_success GPGSM 'fail without key and heed user.signingkey x509' '
274266
test_config gpg.format x509 &&
275267
prepare_dst &&
276-
mkdir -p dst/.git/hooks &&
277268
git -C dst config receive.certnonceseed sekrit &&
278-
write_script dst/.git/hooks/post-receive <<-\EOF &&
269+
test_hook -C dst post-receive <<-\EOF &&
279270
# discard the update list
280271
cat >/dev/null
281272
# record the push certificate
@@ -326,10 +317,9 @@ test_expect_success GPGSM 'fail without key and heed user.signingkey x509' '
326317
test_expect_success GPGSSH 'fail without key and heed user.signingkey ssh' '
327318
test_config gpg.format ssh &&
328319
prepare_dst &&
329-
mkdir -p dst/.git/hooks &&
330320
git -C dst config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
331321
git -C dst config receive.certnonceseed sekrit &&
332-
write_script dst/.git/hooks/post-receive <<-\EOF &&
322+
test_hook -C dst post-receive <<-\EOF &&
333323
# discard the update list
334324
cat >/dev/null
335325
# record the push certificate

t/t7113-post-index-change-hook.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ test_expect_success 'setup' '
1717
'
1818

1919
test_expect_success 'test status, add, commit, others trigger hook without flags set' '
20-
mkdir -p .git/hooks &&
21-
write_script .git/hooks/post-index-change <<-\EOF &&
20+
test_hook post-index-change <<-\EOF &&
2221
if test "$1" -eq 1; then
2322
echo "Invalid combination of flags passed to hook; updated_workdir is set." >testfailure
2423
exit 1
@@ -63,7 +62,7 @@ test_expect_success 'test status, add, commit, others trigger hook without flags
6362
'
6463

6564
test_expect_success 'test checkout and reset trigger the hook' '
66-
write_script .git/hooks/post-index-change <<-\EOF &&
65+
test_hook post-index-change <<-\EOF &&
6766
if test "$1" -eq 1 && test "$2" -eq 1; then
6867
echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure
6968
exit 1
@@ -106,7 +105,7 @@ test_expect_success 'test checkout and reset trigger the hook' '
106105
'
107106

108107
test_expect_success 'test reset --mixed and update-index triggers the hook' '
109-
write_script .git/hooks/post-index-change <<-\EOF &&
108+
test_hook post-index-change <<-\EOF &&
110109
if test "$1" -eq 1 && test "$2" -eq 1; then
111110
echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure
112111
exit 1

t/t9001-send-email.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,9 +2288,7 @@ test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
22882288
'
22892289

22902290
test_expect_success $PREREQ 'invoke hook' '
2291-
mkdir -p .git/hooks &&
2292-
2293-
write_script .git/hooks/sendemail-validate <<-\EOF &&
2291+
test_hook sendemail-validate <<-\EOF &&
22942292
# test that we have the correct environment variable, pwd, and
22952293
# argument
22962294
case "$GIT_DIR" in

0 commit comments

Comments
 (0)