#!/bin/sh
# Pre-commit hook to run cargo fmt

# Get list of staged .rs files
STAGED_RS_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.rs$')

if [ -z "$STAGED_RS_FILES" ]; then
    exit 0
fi

# Run cargo fmt
cargo fmt

# Re-stage any files that were formatted
for file in $STAGED_RS_FILES; do
    if [ -f "$file" ]; then
        git add "$file"
    fi
done

exit 0
