38 lines
993 B
Bash
38 lines
993 B
Bash
#!/bin/bash
|
||
|
||
# commit-msg钩子:检查提交信息格式
|
||
|
||
set -e
|
||
|
||
commit_msg_file="$1"
|
||
commit_msg=$(cat "$commit_msg_file")
|
||
|
||
echo "=== 运行commit-msg检查 ==="
|
||
|
||
# 检查提交信息格式
|
||
if ! echo "$commit_msg" | grep -q "^\(feat\|fix\|docs\|style\|refactor\|test\|chore\): "; then
|
||
echo "错误:提交信息格式不正确"
|
||
echo "正确格式:<type>: <description>"
|
||
echo "类型包括:feat、fix、docs、style、refactor、test、chore"
|
||
exit 1
|
||
fi
|
||
|
||
# 检查提交信息长度
|
||
if [ ${#commit_msg} -gt 50 ]; then
|
||
echo "警告:提交信息描述过长(建议不超过50字符)"
|
||
fi
|
||
|
||
# 检查是否包含issue编号
|
||
if ! echo "$commit_msg" | grep -q "#\d\+"; then
|
||
echo "提示:建议在提交信息中包含相关issue编号"
|
||
fi
|
||
|
||
# 检查是否是bootstrap提交
|
||
if echo "$commit_msg" | grep -q "bootstrap"; then
|
||
echo "✓ bootstrap提交,跳过详细检查"
|
||
exit 0
|
||
fi
|
||
|
||
echo "✓ 提交信息格式正确"
|
||
echo "=== commit-msg检查完成 ==="
|