37 lines
1.1 KiB
Bash
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
|
|
|
|
# 仅对 'Forest/Assets/Scripts/' 路径下的文件进行额外检查
|
|
if [[ $FILE == *"Forest/Assets/Scripts/"* ]]; then
|
|
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
|
|
fi
|
|
fi
|
|
fi
|
|
done
|
|
}
|
|
|
|
# 执行检查函数
|
|
check_commit
|
|
|
|
# 检查是否通过
|
|
if [ $? -eq 1 ]; then
|
|
echo "pre-commit 检查失败,取消 commit"
|
|
exit 1
|
|
else
|
|
echo "pre-commit 检查成功,允许 commit"
|
|
exit 0
|
|
fi |