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/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>
Ævar Arnfjörð Bjarmason committed
Mar 17, 2022 at 11:13 UTC
bef805b7d8eed8ab5ee20128acf636a95bcba1f2
9 files changed
+27
-60
t/t0029-core-unsetenvvars.sh
+1
-2
@@ -12,8 +12,7 @@ then
12
fi
13
14
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
16
echo $HOBBES >&2
17
EOF
18
'
t/t1350-config-hooks-path.sh
+2
-2
@@ -6,11 +6,11 @@ test_description='Test the core.hooksPath configuration variable'
6
7
test_expect_success 'set up a pre-commit hook in core.hooksPath' '
8
>actual &&
9
- mkdir -p .git/custom-hooks .git/hooks &&
9
+ mkdir -p .git/custom-hooks &&
10
write_script .git/custom-hooks/pre-commit <<-\EOF &&
11
echo CUSTOM >>actual
12
EOF
13
- write_script .git/hooks/pre-commit <<-\EOF
13
+ test_hook --setup pre-commit <<-\EOF
14
echo NORMAL >>actual
15
EOF
16
'
t/t3404-rebase-interactive.sh
+2
-8
@@ -619,9 +619,7 @@ test_expect_success 'rebase a detached HEAD' '
619
'
620
621
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 &&
623
test -z "$(git diff --cached --check)"
624
EOF
625
echo "monde! " >> file1 &&
@@ -636,8 +634,6 @@ test_expect_success 'rebase a commit violating pre-commit' '
634
'
635
636
test_expect_success 'rebase with a file named HEAD in worktree' '
639
-
640
- rm -fr .git/hooks &&
637
git reset --hard &&
638
git checkout -b branch3 A &&
639
@@ -1688,10 +1684,8 @@ test_expect_success 'valid author header when author contains single quote' '
1684
'
1685
1686
test_expect_success 'post-commit hook is called' '
1691
- test_when_finished "rm -f .git/hooks/post-commit" &&
1687
>actual &&
1693
- mkdir -p .git/hooks &&
1694
- write_script .git/hooks/post-commit <<-\EOS &&
1688
+ test_hook post-commit <<-\EOS &&
1689
git rev-parse HEAD >>actual
1690
EOS
1691
(
t/t3430-rebase-merges.sh
+3
-3
@@ -292,9 +292,9 @@ test_expect_success 'post-rewrite hook and fixups work for merges' '
292
git commit --fixup HEAD same2.t &&
293
fixup="$(git rev-parse HEAD)" &&
294
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
298
299
test_tick &&
300
git rebase -i --autosquash -r HEAD^^^ &&
t/t4150-am.sh
+6
-18
@@ -315,12 +315,10 @@ test_expect_success 'am --patch-format=hg applies hg patch' '
315
'
316
317
test_expect_success 'am with applypatch-msg hook' '
318
- test_when_finished "rm -f .git/hooks/applypatch-msg" &&
318
rm -fr .git/rebase-apply &&
319
git reset --hard &&
320
git checkout first &&
322
- mkdir -p .git/hooks &&
323
- write_script .git/hooks/applypatch-msg <<-\EOF &&
321
+ test_hook applypatch-msg <<-\EOF &&
322
cat "$1" >actual-msg &&
323
echo hook-message >"$1"
324
EOF
@@ -335,12 +333,10 @@ test_expect_success 'am with applypatch-msg hook' '
333
'
334
335
test_expect_success 'am with failing applypatch-msg hook' '
338
- test_when_finished "rm -f .git/hooks/applypatch-msg" &&
336
rm -fr .git/rebase-apply &&
337
git reset --hard &&
338
git checkout first &&
342
- mkdir -p .git/hooks &&
343
- write_script .git/hooks/applypatch-msg <<-\EOF &&
339
+ test_hook applypatch-msg <<-\EOF &&
340
exit 1
341
EOF
342
test_must_fail git am patch1 &&
@@ -350,12 +346,10 @@ test_expect_success 'am with failing applypatch-msg hook' '
346
'
347
348
test_expect_success 'am with pre-applypatch hook' '
353
- test_when_finished "rm -f .git/hooks/pre-applypatch" &&
349
rm -fr .git/rebase-apply &&
350
git reset --hard &&
351
git checkout first &&
357
- mkdir -p .git/hooks &&
358
- write_script .git/hooks/pre-applypatch <<-\EOF &&
352
+ test_hook pre-applypatch <<-\EOF &&
353
git diff first >diff.actual
354
exit 0
355
EOF
@@ -368,12 +362,10 @@ test_expect_success 'am with pre-applypatch hook' '
362
'
363
364
test_expect_success 'am with failing pre-applypatch hook' '
371
- test_when_finished "rm -f .git/hooks/pre-applypatch" &&
365
rm -fr .git/rebase-apply &&
366
git reset --hard &&
367
git checkout first &&
375
- mkdir -p .git/hooks &&
376
- write_script .git/hooks/pre-applypatch <<-\EOF &&
368
+ test_hook pre-applypatch <<-\EOF &&
369
exit 1
370
EOF
371
test_must_fail git am patch1 &&
@@ -383,12 +375,10 @@ test_expect_success 'am with failing pre-applypatch hook' '
375
'
376
377
test_expect_success 'am with post-applypatch hook' '
386
- test_when_finished "rm -f .git/hooks/post-applypatch" &&
378
rm -fr .git/rebase-apply &&
379
git reset --hard &&
380
git checkout first &&
390
- mkdir -p .git/hooks &&
391
- write_script .git/hooks/post-applypatch <<-\EOF &&
381
+ test_hook post-applypatch <<-\EOF &&
382
git rev-parse HEAD >head.actual
383
git diff second >diff.actual
384
exit 0
@@ -403,12 +393,10 @@ test_expect_success 'am with post-applypatch hook' '
393
'
394
395
test_expect_success 'am with failing post-applypatch hook' '
406
- test_when_finished "rm -f .git/hooks/post-applypatch" &&
396
rm -fr .git/rebase-apply &&
397
git reset --hard &&
398
git checkout first &&
410
- mkdir -p .git/hooks &&
411
- write_script .git/hooks/post-applypatch <<-\EOF &&
399
+ test_hook post-applypatch <<-\EOF &&
400
git rev-parse HEAD >head.actual
401
exit 1
402
EOF
t/t5403-post-checkout-hook.sh
+1
-2
@@ -10,8 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
. ./test-lib.sh
11
12
test_expect_success setup '
13
- mkdir -p .git/hooks &&
14
- write_script .git/hooks/post-checkout <<-\EOF &&
13
+ test_hook --setup post-checkout <<-\EOF &&
14
echo "$@" >.git/post-checkout.args
15
EOF
16
test_commit one &&
t/t5534-push-signed.sh
+8
-18
@@ -35,8 +35,7 @@ test_expect_success setup '
35
36
test_expect_success 'unsigned push does not send push certificate' '
37
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 &&
39
# discard the update list
40
cat >/dev/null
41
# record the push certificate
@@ -52,8 +51,7 @@ test_expect_success 'unsigned push does not send push certificate' '
51
52
test_expect_success 'talking with a receiver without push certificate support' '
53
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 &&
55
# discard the update list
56
cat >/dev/null
57
# record the push certificate
@@ -69,22 +67,19 @@ test_expect_success 'talking with a receiver without push certificate support' '
67
68
test_expect_success 'push --signed fails with a receiver without push certificate support' '
69
prepare_dst &&
72
- mkdir -p dst/.git/hooks &&
70
test_must_fail git push --signed dst noop ff +noff 2>err &&
71
test_i18ngrep "the receiving end does not support" err
72
'
73
74
test_expect_success 'push --signed=1 is accepted' '
75
prepare_dst &&
79
- mkdir -p dst/.git/hooks &&
76
test_must_fail git push --signed=1 dst noop ff +noff 2>err &&
77
test_i18ngrep "the receiving end does not support" err
78
'
79
80
test_expect_success GPG 'no certificate for a signed push with no update' '
81
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 &&
83
if test -n "${GIT_PUSH_CERT-}"
84
then
85
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' '
91
92
test_expect_success GPG 'signed push sends push certificate' '
93
prepare_dst &&
99
- mkdir -p dst/.git/hooks &&
94
git -C dst config receive.certnonceseed sekrit &&
101
- write_script dst/.git/hooks/post-receive <<-\EOF &&
95
+ test_hook -C dst post-receive <<-\EOF &&
96
# discard the update list
97
cat >/dev/null
98
# record the push certificate
@@ -139,10 +133,9 @@ test_expect_success GPG 'signed push sends push certificate' '
133
134
test_expect_success GPGSSH 'ssh signed push sends push certificate' '
135
prepare_dst &&
142
- mkdir -p dst/.git/hooks &&
136
git -C dst config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
137
git -C dst config receive.certnonceseed sekrit &&
145
- write_script dst/.git/hooks/post-receive <<-\EOF &&
138
+ test_hook -C dst post-receive <<-\EOF &&
139
# discard the update list
140
cat >/dev/null
141
# record the push certificate
@@ -223,9 +216,8 @@ test_expect_success GPG 'inconsistent push options in signed push not allowed' '
216
217
test_expect_success GPG 'fail without key and heed user.signingkey' '
218
prepare_dst &&
226
- mkdir -p dst/.git/hooks &&
219
git -C dst config receive.certnonceseed sekrit &&
228
- write_script dst/.git/hooks/post-receive <<-\EOF &&
220
+ test_hook -C dst post-receive <<-\EOF &&
221
# discard the update list
222
cat >/dev/null
223
# record the push certificate
@@ -273,9 +265,8 @@ test_expect_success GPG 'fail without key and heed user.signingkey' '
265
test_expect_success GPGSM 'fail without key and heed user.signingkey x509' '
266
test_config gpg.format x509 &&
267
prepare_dst &&
276
- mkdir -p dst/.git/hooks &&
268
git -C dst config receive.certnonceseed sekrit &&
278
- write_script dst/.git/hooks/post-receive <<-\EOF &&
269
+ test_hook -C dst post-receive <<-\EOF &&
270
# discard the update list
271
cat >/dev/null
272
# record the push certificate
@@ -326,10 +317,9 @@ test_expect_success GPGSM 'fail without key and heed user.signingkey x509' '
317
test_expect_success GPGSSH 'fail without key and heed user.signingkey ssh' '
318
test_config gpg.format ssh &&
319
prepare_dst &&
329
- mkdir -p dst/.git/hooks &&
320
git -C dst config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
321
git -C dst config receive.certnonceseed sekrit &&
332
- write_script dst/.git/hooks/post-receive <<-\EOF &&
322
+ test_hook -C dst post-receive <<-\EOF &&
323
# discard the update list
324
cat >/dev/null
325
# record the push certificate
t/t7113-post-index-change-hook.sh
+3
-4
@@ -17,8 +17,7 @@ test_expect_success 'setup' '
17
'
18
19
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 &&
21
if test "$1" -eq 1; then
22
echo "Invalid combination of flags passed to hook; updated_workdir is set." >testfailure
23
exit 1
@@ -63,7 +62,7 @@ test_expect_success 'test status, add, commit, others trigger hook without flags
62
'
63
64
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 &&
66
if test "$1" -eq 1 && test "$2" -eq 1; then
67
echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure
68
exit 1
@@ -106,7 +105,7 @@ test_expect_success 'test checkout and reset trigger the hook' '
105
'
106
107
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 &&
109
if test "$1" -eq 1 && test "$2" -eq 1; then
110
echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure
111
exit 1
t/t9001-send-email.sh
+1
-3
@@ -2288,9 +2288,7 @@ test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2288
'
2289
2290
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 &&
2292
# test that we have the correct environment variable, pwd, and
2293
# argument
2294
case "$GIT_DIR" in