Skip to content

Commit c35ec8c

Browse files
davvidgitster
authored andcommitted
t/t7503-pre-commit-hook.sh: Add GIT_PREFIX tests
Ensure that the pre-commit hook has access to GIT_PREFIX. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f9ad901 commit c35ec8c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

t/t7503-pre-commit-hook.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,38 @@ test_expect_success POSIXPERM '--no-verify with non-executable hook' '
8484
git commit --no-verify -m "more content"
8585
8686
'
87+
chmod +x "$HOOK"
88+
89+
# a hook that checks $GIT_PREFIX and succeeds inside the
90+
# success/ subdirectory only
91+
cat > "$HOOK" <<EOF
92+
#!/bin/sh
93+
test \$GIT_PREFIX = success/
94+
EOF
95+
96+
test_expect_success 'with hook requiring GIT_PREFIX' '
97+
98+
echo "more content" >> file &&
99+
git add file &&
100+
mkdir success &&
101+
(
102+
cd success &&
103+
git commit -m "hook requires GIT_PREFIX = success/"
104+
) &&
105+
rmdir success
106+
'
107+
108+
test_expect_success 'with failing hook requiring GIT_PREFIX' '
109+
110+
echo "more content" >> file &&
111+
git add file &&
112+
mkdir fail &&
113+
(
114+
cd fail &&
115+
test_must_fail git commit -m "hook must fail"
116+
) &&
117+
rmdir fail &&
118+
git checkout -- file
119+
'
87120

88121
test_done

0 commit comments

Comments
 (0)