gitenv

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gitenv isolates test git invocations from the host's git config. It deliberately imports nothing from this repo so that internal tests of low-level packages (e.g. gitrepo, which testutil itself imports) can use it without an import cycle; testutil re-exports it for everyone else.

Index

Constants

View Source
const EnvHermetic = "ENTIRE_TEST_GIT_HERMETIC"

EnvHermetic, when set to a non-empty value, makes emptyConfigPath append per-host HTTP proxy config that routes git HTTPS transport to real external hosts (github.com, gitlab.com) through an unroutable loopback proxy. Any test whose git commands accidentally dial those hosts then fails fast (connection refused at 127.0.0.1:1) instead of reaching the network or prompting for credentials. It is opt-in per test process — the integration TestMain sets it — so unit test packages that don't set it are unaffected. Because Isolated strips all inherited GIT_CONFIG_* env, this config must live in the file GIT_CONFIG_GLOBAL points at (this one), not in GIT_CONFIG_* env entries.

A dead proxy (not url.insteadOf) is used deliberately: insteadOf rewrites the effective URL that git reports on read, which breaks production code that resolves the origin URL to detect the forge (e.g. `entire trail`). The proxy blocks transport only, leaving the configured URL string intact, and is scoped per host so loopback (127.0.0.1) test servers are never proxied.

Regression class: tests accidentally hitting live github.com / the macOS keychain (#1463, 53bc37a88).

Variables

This section is empty.

Functions

func IsolateMain

func IsolateMain()

IsolateMain is IsolateProcess for a TestMain, which has no *testing.T to restore through: the isolation is set process-wide for the whole run via os.Setenv and inherited by every spawned binary and git hook. Inherited GIT_CONFIG_* overrides are neutralized (GIT_CONFIG_COUNT=0 disables the indexed KEY_/VALUE_ pairs) rather than unset.

func IsolateProcess

func IsolateProcess(t *testing.T)

IsolateProcess applies the same git config isolation to the current process. Use this in tests that exercise production code paths which invoke git with os.Environ(). All inherited GIT_CONFIG_* variables are cleared before the isolation overrides are set, so values such as GIT_CONFIG_PARAMETERS or indexed KEY_/VALUE_ overrides cannot leak into child git invocations.

func Isolated

func Isolated() []string

Isolated returns os.Environ() with git isolation variables set. This prevents user/system git config (global gitignore, aliases, etc.) from affecting test behavior. Use this for any exec.Command that runs git or the CLI binary in integration tests.

See https://git-scm.com/docs/git#Documentation/git.txt-GITCONFIGGLOBAL

Every inherited GIT_CONFIG_* entry is filtered out — including GIT_CONFIG_PARAMETERS and the indexed KEY_/VALUE_ pairs that can inject `git -c` overrides — so our explicit isolation overrides take effect regardless of parent env.

func Run

func Run(t *testing.T, dir string, args ...string) string

Run runs one git command in dir with an isolated git config, failing the test on error and returning combined output.

Types

This section is empty.

Jump to

Keyboard shortcuts

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