#!/bin/sh echo "执行pre-commit钩子" check_commit() { # 执行检查 git diff --cached --name-only | while read FILE; do if [[ "$FILE" =~ \.cs$ ]]; then git diff --cached --unified=0 "$FILE" | grep -v '^-' | grep -q "Forbidden to commit" if [ $? -eq 0 ]; then echo "提交失败: $FILE 包含'Forbidden to commit'内容" return 1 fi # 只对Code文件夹下的文件进行检查 if [[ $FILE == *"Forest/Assets/Scripts/"* ]]; then git diff --cached --unified=0 "$FILE" | grep -v '^-' | grep -q "using NPOI.SS.Formula.Functions" if [ $? -eq 0 ]; then echo "Code 提交失败: $FILE 包含'using NPOI.SS.Formula.Functions'内容" return 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