Forest_Client/Tool/GitHook/pre-commit

37 lines
1.1 KiB
Plaintext
Raw Normal View History

2024-10-28 13:08:39 +08:00
#!/bin/sh
2024-10-28 13:20:18 +08:00
echo "执行 pre-commit 钩子"
2024-10-28 13:08:39 +08:00
check_commit() {
# 执行检查
git diff --cached --name-only | while read FILE; do
2024-10-28 13:20:18 +08:00
echo "检查文件: $FILE"
2024-10-28 13:08:39 +08:00
if [[ "$FILE" =~ \.cs$ ]]; then
2024-10-28 13:20:18 +08:00
# 检查 'Forbidden to commit' 字样
if git diff --cached --unified=0 -- "$FILE" | grep -v '^-' | grep -q "Forbidden to commit"; then
echo "提交失败: $FILE 包含 'Forbidden to commit' 内容"
exit 1
2024-10-28 13:08:39 +08:00
fi
2024-10-28 13:20:18 +08:00
# 仅对 'Forest/Assets/Scripts/' 路径下的文件进行额外检查
2024-10-28 13:08:39 +08:00
if [[ $FILE == *"Forest/Assets/Scripts/"* ]]; then
2024-10-28 13:20:18 +08:00
if git diff --cached --unified=0 -- "$FILE" | grep -v '^-' | grep -q "using NPOI.SS.Formula.Functions"; then
echo "Code 提交失败: $FILE 包含 'using NPOI.SS.Formula.Functions' 内容"
exit 1
2024-10-28 13:08:39 +08:00
fi
fi
fi
done
}
2024-10-28 13:20:18 +08:00
# 执行检查函数
2024-10-28 13:08:39 +08:00
check_commit
2024-10-28 13:20:18 +08:00
# 检查是否通过
2024-10-28 13:08:39 +08:00
if [ $? -eq 1 ]; then
2024-10-28 13:20:18 +08:00
echo "pre-commit 检查失败,取消 commit"
2024-10-28 13:08:39 +08:00
exit 1
else
2024-10-28 13:20:18 +08:00
echo "pre-commit 检查成功,允许 commit"
2024-10-28 13:08:39 +08:00
exit 0
fi