#!/bin/sh
#
# Pre-commit hook that runs Spotless check to ensure code formatting standards.
# To install this hook, run from the repository root:
#   git config core.hooksPath .githooks
#

# Only run Spotless if staged changes include files under src/
if ! git diff --cached --name-only | grep -q '^src/'; then
    echo "No changes in src/, skipping Spotless check."
    exit 0
fi

echo "Running Spotless check..."

# Run spotless check
mvn spotless:check -q

if [ $? -ne 0 ]; then
    echo ""
    echo "❌ Spotless check failed!"
    echo "   Run 'mvn spotless:apply' to fix formatting issues."
    echo ""
    exit 1
fi

echo "✓ Spotless check passed"
exit 0
