Files
gplan-2/tools/hooks/pre-merge-commit
T
DKChan 661c2fcc79 工程(合回链冲突路径修复·工具件): pre-merge-commit 红态处置改为唯一 abort 重来
禁 git commit 续合——该路径只触发提交类钩子,pre-merge-commit/post-merge 零触发,前置检查与推送靠人手补。
配套 .zcode/hooks/worktree-guard.sh(本机件 gitignored,主区直改,无独立提交)去掉 MERGE_HEAD 豁免:主区一切 git commit 一律拦(:175 删 and not has_merge,:176-190 换统一拦截块,不再探测 MERGE_HEAD)。

读数(改完即测铁规):
- bash -n tools/hooks/pre-merge-commit PASS
- bash tools/run_all_gates.sh --gates exit=0【验收通过】闸况与基线一致无新增红;闸壳自检 bash -n × 13 件失败 0
- 守卫自测(归并): bash -n PASS;stdin 五态期望/实测全一致 ①主区 git commit=2 ②主区 merge --no-ff=0 ③worktree 内 commit=0 ④--no-verify=2 ⑤畸形 payload=0
2026-11-08 00:53:09 +08:00

26 lines
1.9 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-merge-commit,2026-11-06 用户裁)——主工作区 git merge 落合并提交前
# 跑最小验证面:tools/run_all_gates.sh --premerge(冒烟测试+单元与集成全套件 4 分片,热导入缓存约 2 分钟)。
# 语义(git 2.45.2.windows.1 本机实测):本钩子拦的是「合并提交」不是「合并动作」——exit≠0 时合并结果
# 已进暂存区、仓库停 MERGE_HEAD 待提交态;处置唯一:git merge --abort 放弃 → 回 worktree 处理 → 重新 git merge --no-ff(禁 git commit 续合:该路径 pre-merge-commit/post-merge 两钩子零触发)。
# 快进合并不触发本钩子(git 语义)——本仓合回铁规恒 --no-ff,漏写时远端 CI 兜底仍在。
# --no-verify 可整体跳过(实测)——仅属用户,agent 禁用(worktree-guard 在案)。
# 仅主工作区触发(worktree 内合并不触发,与 post-merge 同款 git-dir 判别)。
# 冷缓存注意:本机首次跑批前先刷导入($GODOT --headless --path game --editor --quit,约 20 秒),
# 否则冷导入可致套件内建 120 秒超时假红;主工作区 .godot 缓存常驻,日常免此步。
set -u
_GD="$(cd "$(git rev-parse --git-dir)" && pwd)"
_CD="$(cd "$(git rev-parse --git-common-dir)" && pwd)"
[ "$_GD" = "$_CD" ] || exit 0
REPO="$(git -C "$(dirname "$0")" rev-parse --show-toplevel 2>/dev/null || pwd)"
bash "$REPO/tools/run_all_gates.sh" --premerge
RC=$?
if [ "$RC" -ne 0 ]; then
echo "" >&2
echo "[pre-merge-commit] ✗ 前置检查红(读数如上)——合并提交未落,仓库停 MERGE_HEAD 待提交态。" >&2
echo " 处置唯一:git merge --abort 放弃 → 回 worktree 处理 → 重新 git merge --no-ff(禁 git commit 续合:两合回钩子零触发)。" >&2
exit 1
fi
echo "[pre-merge-commit] ✓ 前置检查绿——合并提交继续。"
exit 0