testutils

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: MIT Imports: 13 Imported by: 0

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
}

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