cosmonarchy-bw-prerelease/tools/hooks/pre-commit
Kenny Udovic 36cc26b464 25 August 2026 -- tbl encoder decoder and image.tbl.txt loader
Ported from cosmonarchy-bw-release fe42f19. The .tbl.txt sources were
regenerated from this repo's own .tbl binaries rather than copied, so
images.tbl.txt and unitnames.tbl.txt carry the prerelease strings
(Askosi Sons of Ash, Faction Selection Askosi, Terran Fleshthief,
Forerunner Lumen) instead of the release ones.

tools/tbl is committed as real files here; in the release repo it is a
bare gitlink with no .gitmodules, so it comes out empty on clone.
2026-08-25 20:08:20 -04:00

37 lines
1.1 KiB
Bash
Executable File

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