.git hooks校验提交信息

#!/bin/sh

echo >&2 start check msg...
#test "" = "$(grep '^Signed-off-by: ' "$1" |
#	 sort | uniq -c | sed -e '/^[ 	]*1[ 	]/d')" || {
#	echo >&2 Duplicate Signed-off-by lines.
#        echo >&2 No 2025.10.23.
#	exit 1
#}
#dos2unix .git/hooks/pre-commit

commit_msg_file="$1"

# 跳过 merge 提交(以 Merge 开头)
if head -n1 "$commit_msg_file" | grep -q "^Merge "; then
    exit 0
fi

# 检查是否包含版本日期
if ! grep -q "2025.09.10" "$commit_msg_file"; then
    echo >&2 "❌ Commit message must contain '2025.09.10'."
    exit 1
fi
# 项目人员信息
footer=""
if grep -q "P001" "$commit_msg_file"; then
    # 追加到文件末尾
    footer="经理:张三 开发:wc88 测试:李四"
    printf "%s" "$footer" >> "$commit_msg_file"
fi
if grep -q "P002" "$commit_msg_file"; then
    # 追加到文件末尾
    footer="经理:张三2 开发:wc88 测试:李四2"
    printf "%s" "$footer" >> "$commit_msg_file"
fi
if ! grep -q "wc88" "$commit_msg_file"; then
    echo >&2 "❌ Commit message must contain 'wc88'."
    exit 2
fi

exit 0

项目:P001
功能:自动增加一行
版本时间:2025.09.10

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值