#!/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