From f711421658bda25b0345dc0fd1c0e801a7c139c4 Mon Sep 17 00:00:00 2001 From: ZanzyTHEbar Date: Thu, 19 Feb 2026 14:49:39 +0000 Subject: [PATCH] fix(hooks): skip sub-module packages in pre-commit test step The pre-commit hook naively tested all staged package directories, including those belonging to nested Go modules (internal/fantasy has its own go.mod). Add is_sub_module() check to filter out packages whose directory contains a go.mod file. --- scripts/hooks/pre-commit | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit index d33671771..48f9d9f04 100755 --- a/scripts/hooks/pre-commit +++ b/scripts/hooks/pre-commit @@ -152,17 +152,29 @@ fi # ── Step 4: Test (staged packages only) ────────────────────────────────────── +is_sub_module() { + local dir="${1#./}" + local check="$dir" + while [[ "$check" != "." && -n "$check" ]]; do + if [[ -f "$check/go.mod" ]]; then + return 0 + fi + check=$(dirname "$check") + done + return 1 +} + run_tests() { - # Only test packages that have staged changes — keeps it fast. - # Fallback to ./... if package detection fails. local pkgs="$STAGED_PKGS" if [[ -z "$pkgs" ]]; then pkgs="./..." fi - # Filter to packages that actually have _test.go files local testable="" for pkg in $pkgs; do + if is_sub_module "$pkg"; then + continue + fi if ls "${pkg}"/*_test.go >/dev/null 2>&1; then testable="$testable $pkg" fi