gittest

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package gittest provides utilities for testing git repositories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmdAs

func CmdAs(ts *testscript.TestScript, neg bool, args []string)

CmdAs sets the author and committer of the commits that follow.

as 'User Name <user@example.com>'

func CmdAt

func CmdAt(ts *testscript.TestScript, neg bool, args []string)

CmdAt sets the author and commit time of the commits that follow.

at <YYYY-MM-DDTHH:MM:SS>

func CmdGit

func CmdGit(ts *testscript.TestScript, neg bool, args []string)

CmdGit runs a git command in the repository.

[!] git [args ...]

func CondGitVersion added in v0.6.0

func CondGitVersion(wantStr string) (bool, error)

CondGitVersion checks if the current version of Git is at least the given version.

Types

type Config

type Config map[string]string

Config is a set of Git configuration values.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig is the default Git configuration for all test repositories.

func (Config) Env

func (c Config) Env() []string

Env generates a list of environment variable assignments that will have the same effect as setting these configuration values in a Git repository. This is suitable for passing to exec.Cmd.Env.

func (Config) EnvMap

func (c Config) EnvMap() map[string]string

EnvMap generates a map of environment variable assignments that will have the same effect as setting these configuration values in a Git repository.

type Fixture

type Fixture struct {
	// contains filtered or unexported fields
}

Fixture is a temporary directory that contains a Git repository built from a testscript file.

func LoadFixtureFile

func LoadFixtureFile(path string) (_ *Fixture, err error)

LoadFixtureFile loads a fixture file from the given path. The fixture file is expected to be testscript file that runs a series of git commands to set up a Git repository.

func LoadFixtureScript

func LoadFixtureScript(script []byte) (_ *Fixture, err error)

LoadFixtureScript loads a fixture from the testscript. It has access to the following commands in addition to testscript defaults:

func (*Fixture) Cleanup

func (f *Fixture) Cleanup()

Cleanup removes the temporary directory created by the fixture.

func (*Fixture) Dir

func (f *Fixture) Dir() string

Dir returns the directory of the fixture.

type Version added in v0.6.0

type Version struct {
	Major, Minor, Patch int
}

Version is a Git version string.

func ParseVersion added in v0.6.0

func ParseVersion(orig string) (Version, error)

ParseVersion parses a Git version string. This must be in one of the following formats:

git version X.Y.Z (...)
git version X.Y.Z
X.Y.Z
X.Y
X

Where X, Y, and Z are integers.

func (Version) Compare added in v0.6.0

func (v Version) Compare(other Version) int

Compare compares two versions. It returns a negative value if v is less than other, zero if they are equal, and a positive value if v is greater than other.

func (Version) String added in v0.6.0

func (v Version) String() string

Jump to

Keyboard shortcuts

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