1
0
Files
nex/scripts/git-hooks/prepare-commit-msg
lanyuanxiaoyao c04a13bf8a refactor: 重写 Git hooks 体系,委托已有检查、新增模板与 LFS 校验
pre-commit 代码检查改为委托 _backend-lint / _versionctl-lint / _frontend-check,新增 LFS 指针校验;commit-msg 新增多行空行格式校验和模板注释忽略,移除 CJK/Python 字符集检测;新增 prepare-commit-msg 提交信息模板;hooks-install 增加 source 文件存在性校验;前端 check 补入 tsc -b 类型检查并修复暴露的类型错误
2026-05-06 13:44:28 +08:00

50 lines
774 B
Bash
Executable File

#!/bin/sh
set -e
MSG_FILE=$1
MSG_SOURCE=$2
case "$MSG_SOURCE" in
"") ;;
*) exit 0 ;;
esac
if [ ! -f "$MSG_FILE" ]; then
exit 0
fi
has_content=0
while IFS= read -r line || [ -n "$line" ]; do
case "$line" in
''|\#*) ;;
*)
has_content=1
break
;;
esac
done < "$MSG_FILE"
if [ "$has_content" -eq 1 ]; then
exit 0
fi
tmp_file=${MSG_FILE}.nex-template.$$
{
cat <<'EOF'
# <类型>: <简短中文描述>
#
# <详细说明>
#
# 类型: feat / fix / refactor / docs / style / test / chore
# 示例: feat: 添加供应商批量管理功能
EOF
if [ -s "$MSG_FILE" ]; then
printf '\n'
while IFS= read -r line || [ -n "$line" ]; do
printf '%s\n' "$line"
done < "$MSG_FILE"
fi
} > "$tmp_file"
mv "$tmp_file" "$MSG_FILE"