Forest_Client/Tool/GitHook/pre-commit

37 lines
1.1 KiB
Bash

#!/bin/sh
echo "执行 pre-commit 钩子"
check_commit() {
# 执行检查
git diff --cached --name-only | while read FILE; do
echo "检查文件: $FILE"
if [[ "$FILE" =~ \.cs$ ]]; then
# 检查 '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
fi
# 检查所有以 'using NPOI.' 开头的引用
if [[ $FILE == *"Forest/Assets/Scripts/"* ]]; then
if git diff --cached --unified=0 -- "$FILE" | grep -v '^-' | grep -q "using NPOI\."; then
echo "Code 提交失败: $FILE 包含 'using NPOI.' 的内容"
exit 1
fi
fi
fi
done
}
# 执行检查函数
check_commit
# 检查是否通过
if [ $? -eq 1 ]; then
echo "pre-commit 检查失败,取消 commit"
exit 1
else
echo "pre-commit 检查成功,允许 commit"
exit 0
fi