safegit v0.26.0 /internal/testutil
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

Go go
const IdentityName  = "Test"

The deterministic identity every repo these helpers build commits under.

#IdentityEmail

Go go
const IdentityEmail = "[email protected]"

#SubmoduleRepo

Go go
type SubmoduleRepo struct

SubmoduleRepo holds paths for a test repo with a submodule.

#InitRepoWithSubmodule

Go go
func InitRepoWithSubmodule(t *testing.T) SubmoduleRepo

InitRepoWithSubmodule creates a test repo containing one submodule.

#InitRepoWithTwoSubmodules

Go go
func InitRepoWithTwoSubmodules(t *testing.T) (SubmoduleRepo, SubmoduleRepo)

InitRepoWithTwoSubmodules creates a test repo containing two submodules.

#InitRepo

Go go
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

Go go
func InitBareRepo(t *testing.T) string

InitBareRepo 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

Go go
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.

Search