mirror of
https://github.com/git/git
synced 2024-09-17 23:41:33 +00:00
hook tests: test for exact "pre-push" hook input
Extend the tests added inec55559f93
(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 inec55559f93
(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>
This commit is contained in:
parent
e6ebfd0e8c
commit
bbd837f040
|
@ -11,7 +11,7 @@ HOOKDIR="$(git rev-parse --git-dir)/hooks"
|
||||||
HOOK="$HOOKDIR/pre-push"
|
HOOK="$HOOKDIR/pre-push"
|
||||||
mkdir -p "$HOOKDIR"
|
mkdir -p "$HOOKDIR"
|
||||||
write_script "$HOOK" <<EOF
|
write_script "$HOOK" <<EOF
|
||||||
cat >/dev/null
|
cat >actual
|
||||||
exit 0
|
exit 0
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
@ -20,10 +20,16 @@ test_expect_success 'setup' '
|
||||||
git init --bare repo1 &&
|
git init --bare repo1 &&
|
||||||
git remote add parent1 repo1 &&
|
git remote add parent1 repo1 &&
|
||||||
test_commit one &&
|
test_commit one &&
|
||||||
git push parent1 HEAD:foreign
|
cat >expect <<-EOF &&
|
||||||
|
HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero)
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_when_finished "rm actual" &&
|
||||||
|
git push parent1 HEAD:foreign &&
|
||||||
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
write_script "$HOOK" <<EOF
|
write_script "$HOOK" <<EOF
|
||||||
cat >/dev/null
|
cat >actual
|
||||||
exit 1
|
exit 1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
@ -32,11 +38,18 @@ export COMMIT1
|
||||||
|
|
||||||
test_expect_success 'push with failing hook' '
|
test_expect_success 'push with failing hook' '
|
||||||
test_commit two &&
|
test_commit two &&
|
||||||
test_must_fail git push parent1 HEAD
|
cat >expect <<-EOF &&
|
||||||
|
HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero)
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_when_finished "rm actual" &&
|
||||||
|
test_must_fail git push parent1 HEAD &&
|
||||||
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--no-verify bypasses hook' '
|
test_expect_success '--no-verify bypasses hook' '
|
||||||
git push --no-verify parent1 HEAD
|
git push --no-verify parent1 HEAD &&
|
||||||
|
test_path_is_missing actual
|
||||||
'
|
'
|
||||||
|
|
||||||
COMMIT2="$(git rev-parse HEAD)"
|
COMMIT2="$(git rev-parse HEAD)"
|
||||||
|
|
Loading…
Reference in a new issue