testutil

package
v0.152.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repo

type Repo struct {
	Dir    string // working tree
	GitDir string // .git
	// contains filtered or unexported fields
}

Repo is a temporary isolated git repository for integration tests.

func Attach

func Attach(t testing.TB, dir string) *Repo

Attach wraps an existing on-disk repository (e.g. a copy made by a test) in a Repo handle, without initializing anything.

func NewRepo

func NewRepo(t testing.TB) *Repo

NewRepo creates a fresh git repo in t.TempDir() with full isolation. The repo is initialised on branch "main" with one empty commit.

func (*Repo) AddRemote

func (r *Repo) AddRemote(name, url string)

AddRemote adds a remote with the given name pointing to url (or another repo's Dir).

func (*Repo) Checkout

func (r *Repo) Checkout(ref string)

Checkout checks out an existing ref.

func (*Repo) Commit

func (r *Repo) Commit(msg string) string

Commit stages all changes and creates a commit with msg. Returns the 40-character commit SHA.

func (*Repo) CreateBranch

func (r *Repo) CreateBranch(name string)

CreateBranch creates and checks out a new branch.

func (*Repo) RunGit

func (r *Repo) RunGit(args ...string) string

RunGit executes `git <args...>` in the repo dir with isolation env. Returns combined stdout (trimmed). t.Fatal on non-zero exit.

func (*Repo) SetRemoteHEAD

func (r *Repo) SetRemoteHEAD(remote, branch string)

SetRemoteHEAD sets refs/remotes/<remote>/HEAD to a symbolic-ref for branch.

func (*Repo) TryGit

func (r *Repo) TryGit(args ...string) (string, error)

TryGit is like RunGit but returns stdout + exit error without failing the test.

func (*Repo) WriteFile

func (r *Repo) WriteFile(path, content string)

WriteFile creates or overwrites a file relative to Dir. Intermediate directories are created as needed. t.Fatal on error.

Jump to

Keyboard shortcuts

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