#!/usr/bin/env bash # 本地硬闸(commit-msg):主题行宽度/句点。git 将消息文件作为 $1 传入—— # 注意不能用 pre-commit 做此事:-m 消息在 prepare-commit-msg 才写入,pre-commit 阶段尚不存在。 msgfile="$1" [ -n "$msgfile" ] && [ -f "$msgfile" ] || exit 0 subject=$(head -1 "$msgfile") [ -n "$subject" ] || exit 0 w=$(python3 -c 'import sys,unicodedata;print(sum(2 if unicodedata.east_asian_width(c) in "WF" else 1 for c in sys.argv[1]))' "$subject") [ "$w" -le 100 ] || { echo "commit-msg: 拒绝——主题行宽 ${w} > 100 列:${subject}" >&2; exit 1; } case "$subject" in *.) echo "commit-msg: 拒绝——主题行不以句点结尾:${subject}" >&2; exit 1 ;; esac exit 0