#!/bin/bash

# Pre-commit hook: auto-format Go code before committing.
# Install: cp scripts/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit

set -euo pipefail

# Auto-format all Go files
gofmt -w .

# Re-stage any files that were reformatted
git diff --name-only -- '*.go' | while read -r f; do
    git add "$f"
done
