ontoref-outreach/site/scripts/hooks/pre-commit

41 lines
1.6 KiB
Text
Raw Normal View History

2026-07-17 01:01:30 +01:00
#!/usr/bin/env bash
# Refuse a commit that would record a hand-edited projection.
#
# Every publishing surface in site/ is derived: the expediente articles and the standalone
# informe from their .ncl, the ADR pages from the spine, htmx-templates/ from its sources.
# Editing the render instead of the source is the failure this repo has already paid for
# twice — the work survives until the next build, and then it is gone without a word.
#
# Installed by `just install-hooks`. Skip a single commit with `git commit --no-verify`.
set -uo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" # → outreach/site
# Only gate commits that touch the site. Work elsewhere in outreach/ has its own rules.
if ! git diff --cached --name-only | grep -q '^site/'; then
exit 0
fi
if ! command -v just > /dev/null 2>&1; then
echo "pre-commit: 'just' not on PATH — cannot run the gates. Commit refused."
echo " install just, or bypass once with: git commit --no-verify"
exit 1
fi
echo "pre-commit: the commit touches site/ — running the gates"
if ! just --justfile "$here/justfile" check; then
cat <<'MSG'
pre-commit: refused. A gate is red, which means something in the working tree does not
reproduce from its source. Fix the SOURCE and regenerate — do not edit the render:
just expedientes # .ncl → the article bodies
just informe # .ncl → the standalone viewer
just adr-pages # spine → the ADR pages
just templates # sources → htmx-templates/
Bypass, knowing what you are doing: git commit --no-verify
MSG
exit 1
fi