Help us shape the future of Go! Take the 2026 Go Developer Survey

testgit

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package testgit runs git in tests under a hermetic config env. Production code must keep the user's real config (credentials, SSH, hooks).

Two entry points cover every git invocation in tests:

  • Hermetic: before production internal/git (or gitroot) runs under a test
  • Run / Combined / CombinedEnv / AllowFailure / CombinedAllowFailure: every test-spawned git subprocess

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowFailure

func AllowFailure(t *testing.T, dir string, extraEnv []string, args ...string) error

AllowFailure runs git with hermetic env and returns the process error (nil on success). Use for expected non-zero exits (e.g. rebase pausing on conflict) when output is unused.

func Combined

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

Combined is Run but returns trimmed combined stdout+stderr.

func CombinedAllowFailure

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

CombinedAllowFailure is AllowFailure but also returns trimmed combined stdout+stderr. Use when a non-zero exit is acceptable and the caller needs the output (e.g. empty-repo log).

func CombinedEnv

func CombinedEnv(t *testing.T, dir string, extraEnv []string, args ...string) string

CombinedEnv is Combined with extra environment entries (e.g. GIT_AUTHOR_DATE=…).

func Hermetic

func Hermetic(t *testing.T)

Hermetic clears global/system git config and templates for this test process so host ~/.gitconfig cannot leak into git. Local repo config set after init still applies.

Call from requireGit (or equivalent) before exercising production code that shells out to git. Test-side spawns should use Run/Combined instead of calling Hermetic alone.

Safe only outside t.Parallel. Unix-only OS support matches the product (linux || darwin).

func Run

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

Run runs git in dir with hermetic env and fatals on non-zero exit.

Types

This section is empty.

Jump to

Keyboard shortcuts

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