1717PLUGIN_ROOT = Path (__file__ ).resolve ().parents [1 ] # hooks/ 的上级 = 插件根
1818sys .path .insert (0 , str (PLUGIN_ROOT / "scripts" ))
1919
20- from detect_lang import ( # noqa: E402
21- LANG_COMMANDS , detect_languages , load_user_config , project_uses_linter , probe_toolchain ,
20+ from detect_lang import (
21+ LANG_COMMANDS ,
22+ detect_languages ,
23+ probe_toolchain ,
24+ project_uses_linter ,
2225)
2326
24-
2527# === git 提交内容安全检查:绝不该进版本库的文件 ===
2628# 目录(路径任一段落匹配即违规):依赖/虚拟环境/构建产物/IDE/缓存
2729GUARD_EXCLUDE_DIRS = {
@@ -43,7 +45,7 @@ def _git(project_root: Path, *args: str) -> str | None:
4345 """跑只读 git 命令;失败(非 git 仓/无 upstream 等)返回 None,由调用方降级"""
4446 try :
4547 proc = subprocess .run (
46- ["git" , * args ], cwd = project_root , capture_output = True , text = True , timeout = 15
48+ ["git" , * args ], cwd = project_root , capture_output = True , check = False , text = True , timeout = 15
4749 )
4850 except (subprocess .TimeoutExpired , OSError , FileNotFoundError ):
4951 return None
@@ -101,7 +103,8 @@ def format_safety_report(violations: list[tuple[str, str, str]]) -> str:
101103
102104
103105def _gate_cache_path (project_root : Path ) -> Path :
104- import hashlib , tempfile
106+ import hashlib
107+ import tempfile
105108 key = hashlib .sha1 (str (project_root .resolve ()).encode ()).hexdigest ()[:12 ]
106109 return Path (tempfile .gettempdir ()) / f"codeguard-gate-{ os .getuid ()} -{ key } .json"
107110
@@ -191,7 +194,7 @@ def check(lang: str):
191194 return (lang , None , f"{ lang } 项目未接入(缺 linter 配置文件),本次未验证" )
192195 try :
193196 proc = subprocess .run (
194- gate_cmd , cwd = project_root , capture_output = True , text = True , timeout = timeout
197+ gate_cmd , cwd = project_root , capture_output = True , check = False , text = True , timeout = timeout
195198 )
196199 except subprocess .TimeoutExpired :
197200 return (lang , None , f"{ lang } 检查超时(>{ timeout } s),本次未验证" )
@@ -217,7 +220,7 @@ def check(lang: str):
217220 for r in results : # pool.map 保序,输出与语言表顺序一致
218221 if r is None :
219222 continue
220- lang , failure , skip = r
223+ _ , failure , skip = r
221224 if failure :
222225 failures .append (failure )
223226 if skip :
0 commit comments