Skip to content

EMBED-AND-CI-06: Pre-commit gate on staged docs

Scoping a validate run to staged markdown in a git hook so commits with errors are blocked.

Builds on: EMBED-AND-CI-05: Fail CI on the exit code

A terminal session: the command as you’d run it, followed by the output it prints; trailing comments note the exit status.

.git/hooks/pre-commit
#!/bin/sh
changed=$(git diff --cached --name-only --diff-filter=ACM -- '*.md')
[ -z "$changed" ] && exit 0
npx markdown-contract validate docs --include $(echo "$changed" | sed 's|^docs/||')
# nonzero exit aborts the commit
  • CLI validate --include
  • exit code as the hook gate