#!/bin/sh
# Sanity checks run only when pushing to main.
# Feature branches push freely.

while read -r local_ref local_sha remote_ref remote_sha; do
    if echo "$remote_ref" | grep -q "refs/heads/main"; then
        echo "→ Pushing to main — running sanity checks..."
        make check
        if [ $? -ne 0 ]; then
            echo ""
            echo "✗ Sanity checks failed. Fix issues before pushing to main."
            echo "  Run 'make fix' to auto-fix lint and format issues."
            exit 1
        fi
        echo "✓ All checks passed."
    fi
done

exit 0
