#!/bin/sh
# Pre-commit hook to ensure code is formatted with cargo fmt

echo "Running cargo fmt check..."

# Check if cargo fmt would make any changes
if ! cargo fmt -- --check > /dev/null 2>&1; then
    echo "❌ Code is not formatted! Running cargo fmt..."
    cargo fmt
    echo "✓ Code has been formatted. Please review changes and commit again."
    exit 1
fi

echo "✓ Code formatting is correct"
exit 0
