beads/internal/testutil/git_test_hooks.go
Pablo LION f81b9b767c
Test isolation follow-up: consolidate and guard hooksPath leakage (#2234) (#2237)
* Stabilize hook-related tests by forcing repo-local hooksPath

* Harden git test repo isolation from global hooksPath (#2234)
2026-03-01 14:41:08 -08:00

22 lines
629 B
Go

package testutil
import (
"fmt"
"os/exec"
"strings"
)
// ForceRepoLocalHooksPath configures a git test repository to use .git/hooks
// regardless of any global core.hooksPath configuration.
func ForceRepoLocalHooksPath(repoDir string) error {
cmd := exec.Command("git", "config", "core.hooksPath", ".git/hooks")
cmd.Dir = repoDir
if out, err := cmd.CombinedOutput(); err != nil {
trimmed := strings.TrimSpace(string(out))
if trimmed != "" {
return fmt.Errorf("set core.hooksPath in %s: %w (output: %s)", repoDir, err, trimmed)
}
return fmt.Errorf("set core.hooksPath in %s: %w", repoDir, err)
}
return nil
}