@minonl/dia 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1251,6 +1251,8 @@ if [ "$adopted" = 1 ]; then
1251
1251
  fi
1252
1252
 
1253
1253
  # 链式:仓库自己的钩子(simple-git-hooks 等管理器生成在 <common>/hooks)
1254
+ # 若当前就是从管理器钩子里的 RC 进来的,再链回去会自递归 → 直接结束
1255
+ if [ "${DIA_WT_IN_MANAGER_HOOK:-0}" = "1" ]; then exit 0; fi
1254
1256
  orig="$common/hooks/$name"
1255
1257
  if [ -x "$orig" ] && [ "$orig" != "$0" ]; then
1256
1258
  if [ "$name" = "pre-push" ] && [ ${#push_lines[@]} -gt 0 ]; then
@@ -1435,10 +1437,22 @@ PYCHK
1435
1437
  # 由 simple-git-hooks 生成的钩子 source 本文件(SIMPLE_GIT_HOOKS_RC)
1436
1438
  # 只对已 adopt 的仓生效;未 adopt → 直接返回
1437
1439
  if command -v dia >/dev/null 2>&1; then
1440
+ export DIA_WT_IN_MANAGER_HOOK=1 # 防止守卫再链回管理器钩子(自递归)
1438
1441
  dia wt guard "$(basename "$0")" || exit $?
1439
1442
  fi
1440
1443
  RC
1441
1444
  wt_ensure_env_export SIMPLE_GIT_HOOKS_RC "$rcf"
1445
+ # 迁移残留:本地 hooksPath 指向已删除的目录(如刚从 husky 切过来)→ 撤掉,让管理器写 .git/hooks
1446
+ if [ -n "$prev" ]; then
1447
+ local resolved="$prev"
1448
+ case "$resolved" in /*) ;; *) resolved="$repo/$resolved" ;; esac
1449
+ if [ ! -d "$resolved" ]; then
1450
+ git -C "$repo" config --local --unset core.hooksPath 2>/dev/null || true
1451
+ echo "[dia-wt] 清理失效的本地 core.hooksPath($prev 已不存在)" >&2
1452
+ else
1453
+ echo "[dia-wt] ⚠️ 本仓仍设有 core.hooksPath=$prev(会覆盖管理器钩子),请确认后移除" >&2
1454
+ fi
1455
+ fi
1442
1456
  python3 - "$cfg" "$repo" "$def" "$template" "$prev" <<'PYG'
1443
1457
  import json, sys, datetime
1444
1458
  cfg, repo, br, tmpl, prev = sys.argv[1:6]
@@ -1551,6 +1565,7 @@ cmd_doctor() {
1551
1565
  cat > "$rcf" <<'RC'
1552
1566
  # 由 simple-git-hooks 生成的钩子 source 本文件(SIMPLE_GIT_HOOKS_RC)
1553
1567
  if command -v dia >/dev/null 2>&1; then
1568
+ export DIA_WT_IN_MANAGER_HOOK=1 # 防止守卫再链回管理器钩子(自递归)
1554
1569
  dia wt guard "$(basename "$0")" || exit $?
1555
1570
  fi
1556
1571
  RC
@@ -61,6 +61,14 @@ grep -q "SIMPLE_GIT_HOOKS_RC" "$HOME/.zshenv" 2>/dev/null && ok "shell rc 注入
61
61
  bash "$WT" doctor "$RN" >/dev/null 2>&1 && ok "npm 仓 doctor 通过" || bad "npm 仓 doctor 失败"
62
62
  (cd "$RN" && DIA_WT_GUARD_PROBE=1 bash "$WT" guard pre-commit >/dev/null 2>&1) && bad "guard 未拦截 main 提交" || ok "guard 拦截 main 提交"
63
63
 
64
+ # RC 注入不得自递归:模拟管理器钩子(source RC 后应直接结束,不再链回自己)
65
+ RC="$( wt_hooks_rc_dir 2>/dev/null || true )"; true
66
+ printf '#!/usr/bin/env bash\nset -e\nname=pre-commit\nsource "$SIMPLE_GIT_HOOKS_RC"\n' > "$TD/pre-commit"
67
+ chmod +x "$TD/pre-commit"
68
+ (cd "$RN" && timeout 10 env SIMPLE_GIT_HOOKS_RC="$DIA_ROOT/hooks/simple-git-hooks-rc.sh" "$TD/pre-commit" >/tmp/rc.log 2>&1)
69
+ rc=$?; [ "$rc" != 124 ] && ok "RC 注入不自递归(main 上被守卫拦截,退出码 $rc)" || bad "RC 注入自递归/超时"
70
+ cd - >/dev/null
71
+
64
72
  # 全局配置残留检查:旧版全局钩子目录 → doctor FAIL
65
73
  LEGACY="$TD/legacy-hooks"; mkdir -p "$LEGACY"
66
74
  printf '#!/usr/bin/env bash\n# dia-wt guard(旧)\nexit 0\n' > "$LEGACY/pre-commit"; chmod +x "$LEGACY/pre-commit"