On this page
Package testutil provides shared test helpers for creating temporary git repos, used across internal/*_test.go packages to avoid duplicating boilerplate.
#internal/testutil
#internal/testutil
Package testutil provides shared test helpers for creating temporary git repos, used across internal/*_test.go packages to avoid duplicating boilerplate.
This package intentionally does NOT import internal/repo (or any other internal/* package) to avoid import cycles -- internal/git is at the bottom of the dependency graph and its tests need these helpers too.
#IdentityName
const IdentityName = "Test"The deterministic identity every repo these helpers build commits under.
#IdentityEmail
const IdentityEmail = "[email protected]"#SubmoduleRepo
type SubmoduleRepo structSubmoduleRepo holds paths for a test repo with a submodule.
#InitRepoWithSubmodule
func InitRepoWithSubmodule(t *testing.T) SubmoduleRepoInitRepoWithSubmodule creates a test repo containing one submodule.
#InitRepoWithTwoSubmodules
func InitRepoWithTwoSubmodules(t *testing.T) (SubmoduleRepo, SubmoduleRepo)InitRepoWithTwoSubmodules creates a test repo containing two submodules.
#InitRepo
func InitRepo(t *testing.T, safegitInit func(gitDir string) error) (repoDir, gitDir, safegitDir string)InitRepo creates a temp git repo with a seed file ("seed.txt") and initial commit, runs the provided safegitInit function to set up .git/safegit/, and returns (repoDir, gitDir, safegitDir).
Callers pass repo.Init as safegitInit:
dir, gitDir, sgDir := testutil.InitRepo(t, repo.Init)
#InitBareRepo
func InitBareRepo(t *testing.T) stringInitBareRepo creates a temp git repo with an allow-empty initial commit (no seed file, no safegit init). Returns the repo directory. Suitable for packages like git and index that don't need safegit infrastructure.
#Chdir
func Chdir(t *testing.T, dir string)Chdir changes into dir for the duration of the test, restoring the original working directory on cleanup. A failed restore fails the test: leaving a suite in the wrong directory corrupts every test after it.