echo "Running pre-commit checks..."
echo "Checking code formatting..."
if ! cargo fmt --check; then
echo "🔧 Auto-fixing code formatting..."
cargo fmt
if [ -n "$(git diff --name-only)" ]; then
echo "📝 Adding formatted files to git..."
git add $(git diff --name-only)
echo "✅ Code formatting fixed and files added to staging area."
else
echo "✅ Code formatting fixed (no changes needed)."
fi
else
echo "✅ Code formatting is already correct."
fi
echo "Running clippy..."
if ! cargo clippy --all-targets -- -D warnings; then
echo "❌ Clippy check failed."
exit 1
fi
echo "Running tests..."
if ! cargo test; then
echo "❌ Tests failed."
exit 1
fi
echo "✅ All pre-commit checks passed!"