pre-commit 557 B

12345678910111213
  1. #!/usr/bin/env bash
  2. # 知识库提交前校验:暂存区含 docs/参考资料/知识库 变更时自动运行校验脚本。
  3. # 阻断不合规提交(返回非 0 时 git commit 会失败),可用 git commit --no-verify 跳过。
  4. set -euo pipefail
  5. ROOT="$(git rev-parse --show-toplevel)"
  6. KB_DIR="docs/参考资料/知识库"
  7. VALIDATOR="$ROOT/docs/scripts/validate_kb.py"
  8. if git diff --cached --name-only -- "$KB_DIR" | grep -q .; then
  9. echo "[pre-commit] 检测到知识库变更,运行校验: $VALIDATOR"
  10. python3 "$VALIDATOR" "$ROOT/$KB_DIR"
  11. fi