From b0deb44a15ba10cff1e8b5543870aed8683e80c9 Mon Sep 17 00:00:00 2001 From: zhangaotian <8474238@qq.com> Date: Mon, 28 Oct 2024 13:20:18 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=B5=8B=E8=AF=95=E3=80=91Hook=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Forest/Assets/Scripts/Gameplay/LevelState.cs | 3 +++ Tool/GitHook/pre-commit | 27 +++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Forest/Assets/Scripts/Gameplay/LevelState.cs b/Forest/Assets/Scripts/Gameplay/LevelState.cs index 823044b..7f0bfef 100644 --- a/Forest/Assets/Scripts/Gameplay/LevelState.cs +++ b/Forest/Assets/Scripts/Gameplay/LevelState.cs @@ -15,6 +15,9 @@ using Object = UnityEngine.Object; using Vector3 = UnityEngine.Vector3; using NPOI.SS.Formula.Functions; +using NPOI.SS.Formula.Functions; +using NPOI.SS.Formula.Functions; + namespace Gameplay.Level { public class LevelState : IState diff --git a/Tool/GitHook/pre-commit b/Tool/GitHook/pre-commit index 031f2d6..6c01a96 100644 --- a/Tool/GitHook/pre-commit +++ b/Tool/GitHook/pre-commit @@ -1,34 +1,37 @@ #!/bin/sh -echo "执行pre-commit钩子" +echo "执行 pre-commit 钩子" check_commit() { # 执行检查 git diff --cached --name-only | while read FILE; do + echo "检查文件: $FILE" 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 + # 检查 '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 - # 只对Code文件夹下的文件进行检查 + + # 仅对 'Forest/Assets/Scripts/' 路径下的文件进行额外检查 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 + 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" + echo "pre-commit 检查失败,取消 commit" exit 1 else - echo "pre-commit 检查成功,允许commit" + echo "pre-commit 检查成功,允许 commit" exit 0 fi \ No newline at end of file