diff options
Diffstat (limited to '.githooks/pre-commit')
| -rwxr-xr-x | .githooks/pre-commit | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..b931987 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,28 @@ +#!/bin/sh +set -e + +# Pre-commit hook: run tests before allowing commit +# Skip with: SKIP_PRE_COMMIT=1 git commit +# Skip on force push: git commit --no-verify + +if [ "$SKIP_PRE_COMMIT" = "1" ]; then + exit 0 +fi + +# Only run tests if C/H/Makefile changed +staged=$(git diff --cached --name-only --diff-filter=d) +if echo "$staged" | grep -qE '\.(c|h)$|^Makefile$'; then + # Run build check + if ! make >/dev/null 2>&1; then + echo "PRE-COMMIT FAILED: build did not succeed." + exit 1 + fi + + # Run tests + if ! make test >/dev/null 2>&1; then + echo "PRE-COMMIT FAILED: tests did not pass." + exit 1 + fi +fi + +exit 0 |