* Stabilize hook-related tests by forcing repo-local hooksPath * Harden git test repo isolation from global hooksPath (#2234)
22 lines
629 B
Go
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
|
|
}
|