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
|
|
|
|
2024-10-28 13:43:08 +08:00
|
|
|
# 检查所有以 'using NPOI.' 开头的引用
|
2024-10-28 13:08:39 +08:00
|
|
|
if [[ $FILE == *"Forest/Assets/Scripts/"* ]]; then
|
2024-10-28 13:43:08 +08:00
|
|
|
if git diff --cached --unified=0 -- "$FILE" | grep -v '^-' | grep -q "using NPOI\."; then
|
|
|
|
echo "Code 提交失败: $FILE 包含 'using NPOI.' 的内容"
|
2024-10-28 13:20:18 +08:00
|
|
|
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
|