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

26 lines
1.7 KiB
Bash
Executable File
Raw Permalink 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 commit 续合,或 git merge --abort 放弃。
# 快进合并不触发本钩子(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 commit 续合本合并;② 放弃整次合并=git merge --abort。" >&2
exit 1
fi
echo "[pre-merge-commit] ✓ 前置检查绿——合并提交继续。"
exit 0