36 lines
977 B
Bash
Executable File
36 lines
977 B
Bash
Executable File
#!/usr/bin/env sh
|
|
set -eu
|
|
|
|
MSG_FILE="$1"
|
|
HEADER="$(sed -n '1p' "$MSG_FILE" | tr -d '\r')"
|
|
|
|
# Allow merge commits and auto-generated revert headers.
|
|
case "$HEADER" in
|
|
"Merge "*|"Revert "*)
|
|
exit 0
|
|
;;
|
|
esac
|
|
|
|
PATTERN='^(feat|enhance|fix|refactor|perf|docs|test|build|ci|chore|revert)(\([a-zA-Z0-9._/-]+\))?: .+$'
|
|
|
|
if ! printf '%s\n' "$HEADER" | grep -Eq "$PATTERN"; then
|
|
echo "提交信息格式不符合规范。" >&2
|
|
echo "要求: <type>(<scope>): <subject> 或 <type>: <subject>" >&2
|
|
echo "示例: enhance(ui): 优化首页按钮交互反馈与提示文案" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Ensure subject contains at least one Chinese character.
|
|
if ! printf '%s\n' "$HEADER" | grep -Eq '[一-龥]'; then
|
|
echo "提交信息必须使用中文(subject 至少包含一个中文字符)。" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Reject sentence-ending Chinese period in header.
|
|
if printf '%s\n' "$HEADER" | grep -Eq '。$'; then
|
|
echo "subject 不要以句号结尾。" >&2
|
|
exit 1
|
|
fi
|
|
|
|
exit 0
|