hook tests: test for exact "pre-push" hook input
Extend the tests added in ec55559f937 (push: Add support for pre-push hooks, 2013-01-13) to exhaustively test for the exact input we're expecting. This ensures that we e.g. don't miss a trailing newline. Appending to a file called "actual" is the established convention in this test for hooks, see the rest of the tests added in ec55559f937 (push: Add support for pre-push hooks, 2013-01-13). Let's follow that convention here. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Feb 18, 2022 at 21:52 UTC
bbd837f040ebeda2d072cdf2bbd26ec61e0f445e
1 file changed
+18
-5
t/t5571-pre-push-hook.sh
+18
-5
@@ -11,7 +11,7 @@ HOOKDIR="$(git rev-parse --git-dir)/hooks"
11
HOOK="$HOOKDIR/pre-push"
12
mkdir -p "$HOOKDIR"
13
write_script "$HOOK" <<EOF
14
-cat >/dev/null
14
+cat >actual
15
exit 0
16
EOF
17
@@ -20,10 +20,16 @@ test_expect_success 'setup' '
20
git init --bare repo1 &&
21
git remote add parent1 repo1 &&
22
test_commit one &&
23
- git push parent1 HEAD:foreign
23
+ cat >expect <<-EOF &&
24
+ HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero)
25
+ EOF
26
+
27
+ test_when_finished "rm actual" &&
28
+ git push parent1 HEAD:foreign &&
29
+ test_cmp expect actual
30
'
31
write_script "$HOOK" <<EOF
26
-cat >/dev/null
32
+cat >actual
33
exit 1
34
EOF
35
@@ -32,11 +38,18 @@ export COMMIT1
38
39
test_expect_success 'push with failing hook' '
40
test_commit two &&
35
- test_must_fail git push parent1 HEAD
41
+ cat >expect <<-EOF &&
42
+ HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero)
43
+ EOF
44
+
45
+ test_when_finished "rm actual" &&
46
+ test_must_fail git push parent1 HEAD &&
47
+ test_cmp expect actual
48
'
49
50
test_expect_success '--no-verify bypasses hook' '
39
- git push --no-verify parent1 HEAD
51
+ git push --no-verify parent1 HEAD &&
52
+ test_path_is_missing actual
53
'
54
55
COMMIT2="$(git rev-parse HEAD)"