Skip to content

Commit bbd837f

Browse files
avargitster
authored andcommitted
hook tests: test for exact "pre-push" hook input
Extend the tests added in ec55559 (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 ec55559 (push: Add support for pre-push hooks, 2013-01-13). Let's follow that convention here. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6ebfd0 commit bbd837f

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

t/t5571-pre-push-hook.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ HOOKDIR="$(git rev-parse --git-dir)/hooks"
1111
HOOK="$HOOKDIR/pre-push"
1212
mkdir -p "$HOOKDIR"
1313
write_script "$HOOK" <<EOF
14-
cat >/dev/null
14+
cat >actual
1515
exit 0
1616
EOF
1717

@@ -20,10 +20,16 @@ test_expect_success 'setup' '
2020
git init --bare repo1 &&
2121
git remote add parent1 repo1 &&
2222
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
2430
'
2531
write_script "$HOOK" <<EOF
26-
cat >/dev/null
32+
cat >actual
2733
exit 1
2834
EOF
2935

@@ -32,11 +38,18 @@ export COMMIT1
3238

3339
test_expect_success 'push with failing hook' '
3440
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
3648
'
3749

3850
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
4053
'
4154

4255
COMMIT2="$(git rev-parse HEAD)"

0 commit comments

Comments
 (0)