test: pin git background gc off in isolated test env (COR-394) · Entire

test: pin git background gc off in isolated test env (COR-394)

72ac486→main·

toothbrush·1mo ago·1 file·+15 added/-4 removed

GitIsolatedEnv/IsolateGitConfigEnv now point git at a config that disables gc.auto, gc.autoDetach, maintenance.auto, and fetch.writeCommitGraph. A detached git gc/git maintenance process could outlive a test while still holding .git/objects open, racing t.TempDir()'s deferred RemoveAll and failing with "directory not empty".

Fixes flaky TestSafelyAdvanceLocalRef_DoesNotReplayDisconnectedChainWhenTargetIsShallow; applied centrally so other git-shelling strategy tests don't regress.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Changes

1

208 unmodified lines

209
210
211
212
213
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
220
227
228
222
229
230
231
232
233
234
235
236

208 unmodified lines

return found

// gitEmptyConfigPath returns the path to an empty file suitable for use as
// GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEM. We use an empty file instead of
// gitEmptyConfigPath returns the path to a config file suitable for use as
// GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEM. We use a real file instead of
// os.DevNull because git on Windows cannot open NUL as a config file.
//
// The file is not strictly empty: it pins background maintenance off so that
// no detached `git gc`/`git maintenance` process lingers after a test holding
// an open handle on the temp repo's .git/objects. Such a lingering process
// races t.TempDir()'s deferred RemoveAll and fails the test with
// "directory not empty" (see COR-394). Suppressing it centrally keeps every
// git-shelling test that uses GitIsolatedEnv/IsolateGitConfigEnv safe.
var gitEmptyConfig string
var gitEmptyConfigOnce sync.Once

func gitEmptyConfigPath() string {
    gitEmptyConfigOnce.Do(func() {
        f, err := os.CreateTemp("", "git-empty-config-*")
        f, err := os.CreateTemp("", "git-isolation-config-*")
        if err != nil {
            panic("create empty git config: " + err.Error())
            panic("create git isolation config: " + err.Error())
        }
        _, err = f.WriteString("[gc]\n\tauto = 0\n\tautoDetach = false\n[maintenance]\n\tauto = false\n[fetch]\n\twriteCommitGraph = false\n")
        if err != nil {
            panic("write git isolation config: " + err.Error())
        }
        _ = f.Close()
        gitEmptyConfig = f.Name()

Mcmd/entire/cli/testutil/testutil.go+15/-4