xgit 0.2.6

A enhanced AI-powered Git tool
#!/bin/bash

echo "Running pre-commit checks..."

# Check formatting and auto-fix if needed
echo "Checking code formatting..."
if ! cargo fmt --check; then
    echo "🔧 Auto-fixing code formatting..."
    cargo fmt
    
    # Check if any files were modified by cargo fmt
    if [ -n "$(git diff --name-only)" ]; then
        echo "📝 Adding formatted files to git..."
        # Add only the files that were actually formatted (changed)
        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

# Run clippy
echo "Running clippy..."
if ! cargo clippy --all-targets -- -D warnings; then
    echo "❌ Clippy check failed."
    exit 1
fi

# Run tests
echo "Running tests..."
if ! cargo test; then
    echo "❌ Tests failed."
    exit 1
fi

echo "✅ All pre-commit checks passed!"