cd "$(dirname "$0")/.."

echo "Running pre-commit checks..."

make test
make check-examples

if [ $? -ne 0 ]; then
    echo "Pre-commit checks failed. Please fix the issues before committing."
    exit 1
fi

# Check if formatting is needed
if ! make fmt-check; then
    echo "Code needs formatting. Running 'make fmt'..."
    make fmt
    echo "Code was reformatted. Please review and re-stage your changes."
    exit 1
fi