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 ¶
- func AllowFailure(t *testing.T, dir string, extraEnv []string, args ...string) error
- func Combined(t *testing.T, dir string, args ...string) string
- func CombinedAllowFailure(t *testing.T, dir string, args ...string) (string, error)
- func CombinedEnv(t *testing.T, dir string, extraEnv []string, args ...string) string
- func Hermetic(t *testing.T)
- func Run(t *testing.T, dir string, args ...string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowFailure ¶
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 CombinedAllowFailure ¶
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 ¶
CombinedEnv is Combined with extra environment entries (e.g. GIT_AUTHOR_DATE=…).
func Hermetic ¶
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).
Types ¶
This section is empty.