Files
scaffold/template/scripts/check-claude-attribution.sh
baozaotumao fb91556832 fix: 署名门禁正则锚定行首,避免误删正文中提到该短语的行
之前正则匹配行内任意位置,导致提交正文里描述性提到署名短语的整行被误删。
改为只匹配行首的真尾注(^\s*co-authored-by:...claude)。
scaffold 本地钩子与 template 门禁脚本同步修正。
已测:正文描述行保留、真尾注剥除。
2026-06-02 02:57:32 -07:00

20 lines
899 B
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# commit-msg 门禁:按 scaffold.includeClaude 策略处理 Claude 署名。
# 由 pre-commit 在 commit-msg 阶段调用,参数 $1 为提交信息文件。
# off(默认):剥除 Co-Authored-By: Claude 行
# on :保留(./scripts/claude-attribution.sh on
set -euo pipefail
msg_file="${1:?用法: check-claude-attribution.sh <commit-msg-file>}"
include="$(git config --get scaffold.includeClaude 2>/dev/null || echo false)"
[ "$include" = "true" ] && exit 0
# 仅匹配行首的真尾注,避免误删正文里提到该短语的行
if grep -qiE '^[[:space:]]*co-authored-by:.*claude' "$msg_file"; then
tmp="$(mktemp)"
grep -viE '^[[:space:]]*co-authored-by:.*claude' "$msg_file" >"$tmp"
mv "$tmp" "$msg_file"
echo "🛡 已移除 Claude 署名(scaffold.includeClaude=false;保留请运行 ./scripts/claude-attribution.sh on"
fi
exit 0