#.githooks/pre-commit
# ....
for kind in GIT_AUTHOR_IDENT GIT_COMMITTER_IDENT; do
ident=$(ident_of "$kind")
if ! grep -Fxq -- "$ident" "$allowed"; then
{
echo "pre-commit: $kind 是 '$ident',不在允许的署名列表里。"
echo " 允许:$(tr '\n' ' ' <"$allowed")"
echo " 常见原因:agent 终端注入了 GIT_AUTHOR_NAME/EMAIL 或 GIT_COMMITTER_NAME/EMAIL。"
echo " 清掉这些环境变量后重试;确实需要新增署名时改 .githooks/allowed-identities。"
} >&2
exit 1
fi
# ....
# .githooks/allowed-identities
AuthorName <example@example.com>
搞githooks可以抵御默认行为,引导agent自己命令内清理环境变量
(举例)他可能就会自行
Remove-Item Env:GIT_COMMITTER_NAME, Env:GIT_COMMITTER_EMAIL, Env:GIT_AUTHOR_NAME, Env:GIT_AUTHOR_EMAIL -ErrorAction SilentlyContinue; git add demo.cs; git commit -F "$env:TEMP\msg-rl-docs.txt" 2>&1 | Out-String; Write-Output "exit=$LASTEXITCODE"
但是这样体验也是很差的。
希望所有人一起发声。
不要说什么自己人工提交就好了。