gitfixture

package
v0.19.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package gitfixture is the SSOT for making every git process a test spawns die with the test that spawned it.

`make check` reds at random: git spawns background maintenance (`gc --auto`) inside a fixture repo and is still writing to .git/objects when t.TempDir()'s cleanup runs RemoveAll on the same tree, producing "unlinkat …/.git/objects: directory not empty" — a teardown race, not a product assertion failure (observed 2026-07-24 in internal/cache's TestStatusline_NoHubSymbol). Nothing in this tree turns gc --auto off, so it is one flake away at any fixture site.

There are two spawn paths, handled by two different mechanisms:

  1. Fixture helpers spawn git directly (exec.Command("git", ...)). Fix at the argv: Args prefixes the flags that disable git's own background maintenance for that one invocation.
  2. PRODUCTION code spawns git while under test — a detached goroutine, for instance, invoking a mirror clone/fetch. That cannot be fixed at a fixture argv. Fix it at the test binary's ENVIRONMENT instead: git reads GIT_CONFIG_COUNT / GIT_CONFIG_KEY_<n> / GIT_CONFIG_VALUE_<n>, and every child process inherits the environment — including a git spawned by production code under test, a git spawned by an exec'd `a2a` binary, and git's own gc --auto grandchild (verified empirically: `-c name=value` on a git invocation propagates via that same env-var mechanism to any git process IT forks, so a single hardened invocation's own internal auto-gc inherits the setting too). HardenEnv does this. Older git ignores unknown env, which is exactly why mechanism 1 stays as the belt.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args

func Args(args ...string) []string

Args returns args prefixed with the flags that disable git's background maintenance for a single fixture invocation (see gitCoreFlags). Flags must land BEFORE the git subcommand, so callers pass this straight to exec.Command("git", gitfixture.Args(subcommandArgs...)...) (or exec.CommandContext's equivalent). The input slice is never mutated — the returned slice is always a fresh allocation.

func HardenEnv

func HardenEnv()

HardenEnv sets the GIT_CONFIG_COUNT/GIT_CONFIG_KEY_<n>/GIT_CONFIG_VALUE_<n> trio (git's documented env-based config mechanism, see git-config(1) "ENVIRONMENT") on the current process, so every git process spawned for the rest of this run picks up the same maintenance-disabling config Args gives fixture call sites directly.

It COMPOSES rather than clobbers: if GIT_CONFIG_COUNT is already N, the four entries are appended at indices N..N+3 and COUNT is set to N+4 — an already-configured GIT_CONFIG_KEY_0/VALUE_0 (say) is left untouched. It is idempotent: calling it twice does not add duplicate entries, so TestMain functions across packages can call it freely without needing to coordinate.

func RunTests

func RunTests(m *testing.M) int

RunTests is the one-liner a package's TestMain calls: HardenEnv, then run the package's tests. See HardenEnv's doc for what this hardens and why.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL