Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,30 @@ set -e
# The relative paths below would otherwise resolve against whatever directory the caller was in.
cd "$(git rev-parse --show-toplevel)"

# The interpreter is chosen by running the probes spec/host-tools.json declares, in its order.
# On native Windows the python.org install registers `py` and not `python3`.
# That name resolves to a Microsoft Store alias stub, and Git Bash inherits the Windows PATH.
# The stub is on PATH and fails when run, so a presence test selects it and the hook then breaks.
# Running the probe is the whole point: it is what tells a working interpreter from a name.
if python3 --version >/dev/null 2>&1; then
run_py() { python3 "$@"; }
elif py -3 --version >/dev/null 2>&1; then
run_py() { py -3 "$@"; }
else
echo "pre-commit: neither 'python3 --version' nor 'py -3 --version' ran, so the doc gates did not run." >&2
echo "pre-commit: see docs/host-setup.md 'What a Host Must Provide'." >&2
exit 1
fi

# The prose gate is scoped to what changed against HEAD, which is the policy for prose.
# A rule is applied as a file is next edited rather than swept across the tree.
# Whole-tree costs about 2.2 seconds where the diff-scoped run costs about 0.13.
# The scope is the working tree rather than the index.
# A partially staged file is therefore judged on all of its edits, not only the staged ones.
# CI re-runs the same rules over the whole tree, which is what makes that affordable here.
python3 scripts/prose_lint.py . --diff HEAD
run_py scripts/prose_lint.py . --diff HEAD

# The eol check is repo-wide rather than diff-scoped, and it is here because it is already fast.
# It reads `.gitattributes` against `.editorconfig` for the whole repository and takes no file list.
# At about 0.04 seconds there is nothing to scope, so scoping it would only make it wrong.
python3 scripts/repo_gate.py --check eol
run_py scripts/repo_gate.py --check eol