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.
This commit is contained in:
ZanzyTHEbar 2026-02-19 14:49:39 +00:00
parent 7ae547d4a5
commit f711421658

View file

@ -152,17 +152,29 @@ fi
# ── Step 4: Test (staged packages only) ────────────────────────────────────── # ── 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() { run_tests() {
# Only test packages that have staged changes — keeps it fast.
# Fallback to ./... if package detection fails.
local pkgs="$STAGED_PKGS" local pkgs="$STAGED_PKGS"
if [[ -z "$pkgs" ]]; then if [[ -z "$pkgs" ]]; then
pkgs="./..." pkgs="./..."
fi fi
# Filter to packages that actually have _test.go files
local testable="" local testable=""
for pkg in $pkgs; do for pkg in $pkgs; do
if is_sub_module "$pkg"; then
continue
fi
if ls "${pkg}"/*_test.go >/dev/null 2>&1; then if ls "${pkg}"/*_test.go >/dev/null 2>&1; then
testable="$testable $pkg" testable="$testable $pkg"
fi fi