Files
eagle0/scripts/pre-commit-gazelle.sh
T
1a751cea6d Improve gazelle pre-commit hook to fail if BUILD files are modified (#4640)
The previous hook ran gazelle but didn't check if it modified any files.
This meant commits could go through with non-canonical BUILD files, causing
gazelle_test to fail in CI.

The new wrapper script:
1. Runs gazelle
2. Checks if any BUILD files were modified
3. Fails with a helpful message if they were, instructing the user to stage changes

Also adds a Pre-Commit Checklist section to CLAUDE.md documenting this behavior.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-06 08:58:07 -08:00

20 lines
554 B
Bash
Executable File

#!/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