davideisinger.com

My personal website
Log | Files | Refs | README

commit 58233de7042f4349f472d2e40c93721ff23f8574
parent 6fe8c6bd4f0e9aa1952da970587b4a43190bcf84
Author: David Eisinger <[email protected]>
Date:   Thu,  8 Oct 2026 02:46:11 -0400

Check spelling before push

Diffstat:
M.githooks/pre-push | 4+++-
MREADME.md | 3+++
Mbin/check-dispatch-hook | 16++++++++++++++++
3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/.githooks/pre-push b/.githooks/pre-push @@ -1,4 +1,6 @@ #!/usr/bin/env bash set -euo pipefail -exec "$(git rev-parse --show-toplevel)/bin/check-dispatch-dates" "$@" +cd "$(git rev-parse --show-toplevel)" +bin/check-dispatch-dates "$@" +exec npx cspell 'content/**/*.md' diff --git a/README.md b/README.md @@ -10,6 +10,9 @@ Enable the repository's Git hooks once per clone: git config core.hooksPath .githooks ``` +Every push also runs `npx cspell 'content/**/*.md'` against the working tree and +blocks on spelling errors. This requires Node.js and npm (`npx`). + Pushing to `origin`'s `main` checks newly added, non-draft Dispatches and existing Dispatches changing from draft to published. Their `date` must be no more than 24 hours old. Edits or renames of already-published posts, draft posts, other diff --git a/bin/check-dispatch-hook b/bin/check-dispatch-hook @@ -16,6 +16,19 @@ with tempfile.TemporaryDirectory(prefix="dispatch-hook-") as directory: root = Path(directory) work = root / "work" work.mkdir() + # Keep these hook tests offline while verifying cspell invocation and failure. + commands = root / "commands" + commands.mkdir() + npx = commands / "npx" + npx.write_text('#!/usr/bin/env python3\n' + 'import os, sys\n' + 'assert sys.argv[1:] == ["cspell", "content/**/*.md"]\n' + 'assert os.path.samefile(os.getcwd(), os.environ["HOOK_TEST_WORK"])\n' + 'if os.environ.get("HOOK_TEST_SPELL_FAIL"):\n' + ' sys.stderr.write("Spelling errors found\\n")\n' + ' sys.exit(1)\n') + npx.chmod(0o755) + env.update(PATH=f"{commands}{os.pathsep}{env['PATH']}", HOOK_TEST_WORK=str(work)) def git(*args): result = subprocess.run(["git", "-C", str(work), *args], env=env, @@ -66,6 +79,9 @@ with tempfile.TemporaryDirectory(prefix="dispatch-hook-") as directory: # Old posts remain editable and renameable without changing their dates. published.write_text(published.read_text() + "Correction.\n") commit() + env["HOOK_TEST_SPELL_FAIL"] = "1" + push(False, message="Spelling errors found") + del env["HOOK_TEST_SPELL_FAIL"] push(True) git("mv", "content/journal/dispatch-published", "content/journal/dispatch-renamed") commit()