From 5a33e5bf2711e7fb563240d10103e889a85efc9a Mon Sep 17 00:00:00 2001 From: Amolith Date: Fri, 24 Jul 2026 21:57:29 -0600 Subject: [PATCH] gitutil: isolate tests from user Git config Git integration tests inherited global and system configuration, allowing host settings such as commit signing to change their behavior. Ignore external Git configuration for the package test process while retaining repository-local configuration created by each fixture. --- internal/gitutil/checkout_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/gitutil/checkout_test.go b/internal/gitutil/checkout_test.go index f4f145a..d0edefa 100644 --- a/internal/gitutil/checkout_test.go +++ b/internal/gitutil/checkout_test.go @@ -4,6 +4,7 @@ import ( "bytes" "compress/gzip" "context" + "fmt" "io" "os" "os/exec" @@ -12,6 +13,34 @@ import ( "testing" ) +func TestMain(m *testing.M) { + for _, variable := range []string{ + "GIT_CONFIG", + "GIT_CONFIG_PARAMETERS", + "GIT_CONFIG_SYSTEM", + } { + if err := os.Unsetenv(variable); err != nil { + panic(fmt.Errorf("unset %s: %w", variable, err)) + } + } + + settings := []struct { + name string + value string + }{ + {name: "GIT_CONFIG_COUNT", value: "0"}, + {name: "GIT_CONFIG_GLOBAL", value: os.DevNull}, + {name: "GIT_CONFIG_NOSYSTEM", value: "1"}, + } + for _, setting := range settings { + if err := os.Setenv(setting.name, setting.value); err != nil { + panic(fmt.Errorf("set %s: %w", setting.name, err)) + } + } + + os.Exit(m.Run()) +} + func TestGenerateAndCheckoutPatch(t *testing.T) { ctx := context.Background() tempDir := t.TempDir() -- 2.51.2