1
0

commit-msg 1.0 KB

1234567891011121314151617181920212223
  1. #!/usr/bin/env bash
  2. # commit-msg 钩子:检查提交信息(语法 + 排版)
  3. # 1. 语法检查:scripts/check-grammar.mjs(基于 git-commit-regulation 规范)
  4. # 2. 排版检查:autocorrect --lint(汉字与英文、数字、符号间空格)
  5. # 启用:git config core.hooksPath .githooks
  6. # 可绕过:git commit --no-verify(远程 CI 门禁不可绕过)
  7. # 当前钩子所在目录 | Current Hook Directory
  8. HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  9. # 1. 语法检查(透传退出码)
  10. node "$HOOK_DIR/../scripts/check-grammar.mjs" --file "$1" || exit $?
  11. # 2. 排版检查:过滤 git 注释行后交给 autocorrect --lint --stdin
  12. # 未安装 autocorrect 时跳过(语法检查仍生效)
  13. if command -v autocorrect > /dev/null 2>&1; then
  14. grep -v '^#' "$1" | autocorrect --lint --stdin || {
  15. echo "错误:提交信息排版不符合 AutoCorrect 规则(汉字与英文、数字、符号间应留空格)"
  16. echo "提示:运行 autocorrect --fix --stdin 或手动调整后重试"
  17. exit 1
  18. }
  19. fi
  20. exit 0