#!/bin/bash
# Pre-commit hook wrapper for gazelle that fails if files are modified.
# This ensures BUILD files are in canonical format before committing.

set -e

# Run gazelle
bazel run //:gazelle 2>/dev/null

# Check if any BUILD files were modified
if ! git diff --quiet -- '*.bazel' '**/BUILD' 'WORKSPACE*'; then
    echo ""
    echo "ERROR: gazelle modified BUILD files. Please stage the changes and retry:"
    echo ""
    git diff --name-only -- '*.bazel' '**/BUILD' 'WORKSPACE*'
    echo ""
    echo "Run: git add -u && git commit"
    exit 1
fi
