Skip to content

Commit d7f1a82

Browse files
authored
chore(pre-commit): document the potential for being out-of-date
1 parent f828aca commit d7f1a82

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

{{ .ProjectSnake }}/githooks/pre-commit

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
git diff --cached --diff-filter=AM --name-only -z | xargs --null --no-run-if-empty bash -c '
44
if [ $# -gt 0 ]; then
55
echo "Formatting staged files: $@"
6+
# Avoid running bazel to build the formatter.
7+
# In theory it's more correct to build it since the one in bazel-out may be out-of-date.
8+
# However a 'git commit' operation should always be fast, and accidental analysis or action cache misses are common.
9+
# So we take the tradeoff of running the existing binary if it exists.
610
if [ -e "bazel-out/bazel_env-opt/bin/tools/bazel_env/bin/format" ]; then
711
bazel-out/bazel_env-opt/bin/tools/bazel_env/bin/format "$@"
812
else
9-
bazel run //:format -- "$@"
13+
bazel run //tools/format -- "$@"
1014
fi
1115

1216
# Check if any of the staged files were modified by the formatter

0 commit comments

Comments
 (0)