cosmonarchy-bw-prerelease/tools/hooks/pre-commit

37 lines
1.1 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# Refuse a commit whose .tbl files do not match their .tbl.txt sources.
#
# The .tbl.txt files are the source of truth; the binary .tbl files are build
# artifacts that the game actually loads. Committing one without the other
# ships strings that nobody authored.
#
# Install: ln -sf ../../tools/hooks/pre-commit .git/hooks/pre-commit
# Bypass: git commit --no-verify
set -e
root=$(git rev-parse --show-toplevel)
# Nothing staged under mpq/ that could affect a table? Nothing to check.
if ! git diff --cached --name-only --diff-filter=ACM | grep -qE '\.tbl(\.txt)?$'; then
exit 0
fi
if ! command -v bun >/dev/null 2>&1; then
echo "pre-commit: bun not found; skipping .tbl freshness check" >&2
exit 0
fi
echo "pre-commit: checking .tbl files against their .tbl.txt sources"
if ! (cd "$root/tools/tbl" && bun run --silent check); then
cat >&2 <<'EOF'
pre-commit: rejected - see STALE entries above.
cd tools/tbl && bun run build # recompile, then stage the .tbl files
git commit --no-verify # or bypass, if you know why
EOF
exit 1
fi