Files
gplan-2/tools/hooks/pre-commit
T

32 lines
1.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 直改车道闸(git pre-commit,2026-10-30 本地 CI 化换代)——提交点现场跑文档域闸
# (tools/run_all_gates.sh --docs,秒级文本扫描):绿=落地,红=中止。
# 代码面提交不再拦(2026-10-30 用户裁:主区直改全面放开)——代码验证归合回后的本地 CI
# (tools/hooks/post-merge 全量跑批;CI 红态下 tools/hooks/post-commit 追绿复验)。
# 合并收尾提交跳过(MERGE_HEAD 在=冲突合并的收尾 commit)——内容归合回后的 CI 全量验。
# --no-verify 绕过仅属用户(agent 侧由 worktree-guard 拦截)。
set -u
REPO="$(git rev-parse --show-toplevel)"
# 合并收尾提交:跳过文档闸,交合回后 CI
[ -f "$(git rev-parse --git-dir)/MERGE_HEAD" ] && exit 0
RC=0
# 收暂存清单(增量档输入):quotepath 关闭保中文名原样,NUL 转行落临时文件传闸机
_LIST="$(mktemp "${TMPDIR:-/tmp}/gates-staged.XXXXXX")" || _LIST=""
if [ -n "$_LIST" ]; then
git -C "$REPO" -c core.quotepath=false diff --cached --name-only -z | tr '\0' '\n' >"$_LIST"
bash "$REPO/tools/run_all_gates.sh" --docs --staged "$_LIST" || RC=$?
rm -f "$_LIST"
else
bash "$REPO/tools/run_all_gates.sh" --docs || RC=$?
fi
if [ "$RC" -eq 0 ]; then
exit 0
elif [ "$RC" -eq 1 ]; then
echo "[直改闸] 文档域闸有新增红,提交已拦。修上方红项后重新 commit,钩子会自动重跑闸;禁跑代码域/游戏类测试,与本次红项无关。" >&2
else
echo "[直改闸] 闸脚本自身故障(退出码 $RC),不是文档红——把本输出原样呈报用户,勿改文档、勿跑替代测试。" >&2
fi
exit 1