testutils

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 12 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

func AddAuthorInfo

func AddAuthorInfo(cmd *exec.Cmd, timestamp *time.Time)

AddAuthorInfo adds environment variables to `cmd.Env` that set the Git author and committer to known values and set the timestamp to `*timestamp`. Then `*timestamp` is moved forward by a minute, so that each commit gets a unique timestamp.

func CleanGitEnv

func CleanGitEnv() []string

CleanGitEnv returns a clean environment for running `git` commands so that they won't be affected by the local environment.

Types

type TestRepo

type TestRepo struct {
	Path string
	// contains filtered or unexported fields
}

TestRepo represents a git repository used for tests.

func NewTestRepo

func NewTestRepo(t *testing.T, bare bool, pattern string) *TestRepo

NewTestRepo creates and initializes a test repository in a temporary directory constructed using `pattern`. The caller must delete the repository by calling `repo.Remove()`.

func (*TestRepo) AddFile

func (repo *TestRepo) AddFile(t *testing.T, relativePath, contents string)

AddFile adds and stages a file in `repo` at path `relativePath` with the specified `contents`. This must be run in a non-bare repository.

func (*TestRepo) Clone

func (repo *TestRepo) Clone(t *testing.T, pattern string) *TestRepo

Clone creates a clone of `repo` at a temporary path constructued using `pattern`. The caller is responsible for removing it when done by calling `Remove()`.

func (*TestRepo) ConfigAdd

func (repo *TestRepo) ConfigAdd(t *testing.T, key, value string)

ConfigAdd adds a key-value pair to the gitconfig in `repo`.

func (*TestRepo) CreateObject

func (repo *TestRepo) CreateObject(
	t *testing.T, otype git.ObjectType, writer func(io.Writer) error,
) git.OID

CreateObject creates a new Git object, of the specified type, in the repository at `repoPath`. `writer` is a function that generates the object contents in `git hash-object` input format.

func (*TestRepo) CreateReferencedOrphan

func (repo *TestRepo) CreateReferencedOrphan(t *testing.T, refname string)

CreateReferencedOrphan creates a simple new orphan commit and points the reference with name `refname` at it. This can be run in a bare or non-bare repository.

func (*TestRepo) GitCommand

func (repo *TestRepo) GitCommand(t *testing.T, args ...string) *exec.Cmd

GitCommand creates an `*exec.Cmd` for running `git` in `repo` with the specified arguments.

func (*TestRepo) Init

func (repo *TestRepo) Init(t *testing.T, bare bool)

Init initializes a git repository at `repo.Path`.

func (*TestRepo) Remove

func (repo *TestRepo) Remove(t *testing.T)

Remove deletes the test repository at `repo.Path`.

func (*TestRepo) Repository

func (repo *TestRepo) Repository(t *testing.T) *git.Repository

Repository returns a `*git.Repository` for `repo`.

func (*TestRepo) UpdateRef

func (repo *TestRepo) UpdateRef(t *testing.T, refname string, oid git.OID)

UpdateRef updates the reference named `refname` to the value `oid`.

Jump to

Keyboard shortcuts

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