Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion husky
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[ "$HUSKY" = "2" ] && set -x
n=$(basename "$0")
s=$(dirname "$(dirname "$0")")/$n
h="$(git rev-parse --git-dir)/hooks/$n"

[ ! -f "$s" ] && exit 0

Expand All @@ -19,4 +20,13 @@ c=$?

[ $c != 0 ] && echo "husky - $n script failed (code $c)"
[ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
exit $c
[ $c != 0 ] && exit $c

if [ -x "$h" ]; then
"$h" "$@"
c=$?
[ $c != 0 ] && echo "husky - $h hook failed (code $c)"
[ $c != 0 ] && exit $c
fi

exit 0
24 changes: 24 additions & 0 deletions test/13_chain_git_hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
. test/functions.sh
setup
install

npx --no-install husky

# Create a custom .git/hooks/pre-commit
mkdir -p .git/hooks
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/sh
echo "custom git hook executed"
exit 0
EOF
chmod +x .git/hooks/pre-commit

# Should execute both husky and original Git hook
git add package.json
echo "echo \"husky hook executed\"" > .husky/pre-commit
output=$(git commit -m "test" 2>&1)
echo "$output" | grep -q "husky hook executed" || error "husky hook should run"
echo "$output" | grep -q "custom git hook executed" || error "custom .git/hooks/pre-commit should run"

rm .git/hooks/pre-commit