gitfixture

package
v0.35.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package gitfixture is the single home for building git repository state in awf's test suites. It exposes two lanes over one opaque Fixture value: a go-git lane that constructs state in process, and a native lane (this package's own os/exec calls) for the states go-git cannot express - registered worktrees, orphan branches, an in-progress merge, and a non-default object format.

The exported surface is backend-neutral: commits are hex strings and repositories are Fixture values, so a consumer never names a go-git or plumbing type to build a fixture. Sig is the one deliberate exception, kept for the internal/git suites that drive go-git directly.

The package deliberately does not import internal/git (tooling/quality-gates:testsupport-zero-internal-deps), so the native lane carries its own copy of the isolated-environment construction rather than reusing the seam's. It is kept out of internal/testsupport so a caller that only needs e.g. testsupport.WriteFile does not pull go-git into its test binary (ADR-0044).

Index

Constants

This section is empty.

Variables

View Source
var Sig = &object.Signature{Name: authorName, Email: authorEmail, When: time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)}

Sig is the fixed commit signature the go-git lane writes. It stays exported for the internal/git suites, which are allowed to drive go-git directly and need the same identity on the commits they build by hand.

Functions

func Add added in v0.30.0

func Add(t testing.TB, f Fixture, paths ...string)

Add stages paths that already exist in the worktree, including a symlink the test created itself.

func AddAll added in v0.30.0

func AddAll(t testing.TB, f Fixture)

AddAll stages every change in the worktree, matching `git add -A` at the repository root.

func CheckoutNewBranch added in v0.30.0

func CheckoutNewBranch(t testing.TB, f Fixture, name, at string)

CheckoutNewBranch creates a branch at the given commit and checks it out, so a fixture can put history on a branch other than the initial one.

func Commit

func Commit(t testing.TB, f Fixture, msg string, write map[string]string, remove ...string) string

Commit writes/removes the given paths in the fixture's worktree, stages them, and commits with Sig, returning the commit's hex hash.

func Graft added in v0.30.0

func Graft(t testing.TB, f Fixture, msg, treeFrom string, parents ...string) string

Graft writes a commit object directly, taking its tree from treeFrom and its parents as given, without moving any reference. It builds the shapes an ordinary commit cannot reach, such as a merge whose tree deliberately differs from its first parent's.

func Merge added in v0.22.0

func Merge(t testing.TB, f Fixture, msg string, parents ...string) string

Merge creates a commit whose tree is the current index, with the given parents in order (the first is the first parent), so a fixture can exercise first-parent range semantics. It allows an empty commit, so a merge can integrate a branch whose tree already matches HEAD, and with no parents named it simply commits the index on top of HEAD.

func NativeAdd added in v0.30.0

func NativeAdd(t *testing.T, f Fixture, paths ...string)

NativeAdd stages the named paths.

func NativeAddAllExcept added in v0.30.0

func NativeAddAllExcept(t *testing.T, f Fixture, exclude ...string)

NativeAddAllExcept stages every change below the repository root except the given pathspecs, so a fixture can commit its own files while leaving a managed worktree root untouched.

func NativeAnnotatedTag added in v0.30.0

func NativeAnnotatedTag(t *testing.T, f Fixture, name, target string)

NativeAnnotatedTag creates an annotated tag at target.

func NativeBranch added in v0.30.0

func NativeBranch(t *testing.T, f Fixture, name string)

NativeBranch creates a branch at HEAD.

func NativeBranchForce added in v0.30.0

func NativeBranchForce(t *testing.T, f Fixture, name, target string)

NativeBranchForce points a branch at target, creating or moving it.

func NativeCatFile added in v0.30.0

func NativeCatFile(t *testing.T, f Fixture, objectType, rev string) []byte

NativeCatFile returns the exact bytes of one object.

func NativeCheckout added in v0.30.0

func NativeCheckout(t *testing.T, f Fixture, ref string)

NativeCheckout checks out an existing reference.

func NativeCheckoutNewBranch added in v0.30.0

func NativeCheckoutNewBranch(t *testing.T, f Fixture, name, target string)

NativeCheckoutNewBranch creates and checks out a branch at target.

func NativeCheckoutOrphan added in v0.30.0

func NativeCheckoutOrphan(t *testing.T, f Fixture, name string)

NativeCheckoutOrphan starts an orphan branch, the parentless history go-git cannot check out.

func NativeCommit added in v0.30.0

func NativeCommit(t *testing.T, f Fixture, msg string)

NativeCommit commits the staged tree with the fixture identity.

func NativeCommitAllowEmpty added in v0.30.0

func NativeCommitAllowEmpty(t *testing.T, f Fixture, msg string) string

NativeCommitAllowEmpty creates an unsigned commit with the fixture identity.

func NativeConfig added in v0.30.0

func NativeConfig(t *testing.T, f Fixture, key, value string)

NativeConfig sets a repository-local configuration value in a disposable fixture.

func NativeGitPath added in v0.30.0

func NativeGitPath(t *testing.T, f Fixture, name string) string

NativeGitPath resolves a path inside the repository's git directory, such as the MERGE_HEAD marker of an in-progress merge.

func NativeHashObject added in v0.30.0

func NativeHashObject(t *testing.T, f Fixture, objectType string, body []byte) string

NativeHashObject writes exact object bytes and returns the new object ID.

func NativeLightweightTag added in v0.30.0

func NativeLightweightTag(t *testing.T, f Fixture, name, target string)

NativeLightweightTag creates a lightweight tag at target.

func NativeMergeAbort added in v0.30.0

func NativeMergeAbort(t *testing.T, f Fixture)

NativeMergeAbort abandons an in-progress merge.

func NativeRemoveAll added in v0.30.0

func NativeRemoveAll(t *testing.T, f Fixture)

NativeRemoveAll removes every tracked path from the index and worktree, emptying an orphan branch before it takes its own content.

func NativeRevParse added in v0.30.0

func NativeRevParse(t *testing.T, f Fixture, rev string) string

NativeRevParse resolves a revision to its hex object id.

func NativeRevisionExists added in v0.30.0

func NativeRevisionExists(t *testing.T, f Fixture, rev string) bool

NativeRevisionExists reports whether a revision resolves, covering both a branch reference and a pseudo-reference such as MERGE_HEAD. Only exit 1 is an answer: --verify --quiet reserves it for "does not resolve" and every other nonzero exit is a fault, so reading them all as absent would turn a broken fixture into a confident negative and pass a must-be-absent assertion for the wrong reason.

func NativeRun added in v0.30.0

func NativeRun(f Fixture, args ...string) (string, error)

NativeRun executes Git in a disposable fixture and returns combined output and the exact process error.

func NativeSSHKey added in v0.30.0

func NativeSSHKey(t *testing.T) (string, string)

NativeSSHKey generates one passwordless Ed25519 signing key and returns its private path and option-free public record.

func NativeSignedCommit added in v0.30.0

func NativeSignedCommit(t *testing.T, f Fixture, msg, privateKey string) string

NativeSignedCommit creates one genuinely SSH-signed commit with the fixture identity.

func NativeSignedCommitAs added in v0.30.0

func NativeSignedCommitAs(t *testing.T, f Fixture, msg, privateKey, name, email string) string

NativeSignedCommitAs creates one genuinely SSH-signed commit with an exact identity.

func NativeUpdateRef added in v0.30.0

func NativeUpdateRef(t *testing.T, f Fixture, ref, target string)

NativeUpdateRef points one exact reference at an existing object ID.

func NativeWorktreeAdd added in v0.30.0

func NativeWorktreeAdd(t *testing.T, f Fixture, path, branch string)

NativeWorktreeAdd registers a linked worktree at path on a new branch.

func NativeWorktreeAddDetached added in v0.30.0

func NativeWorktreeAddDetached(t *testing.T, f Fixture, path, rev string)

NativeWorktreeAddDetached registers a linked worktree at path with a detached HEAD at rev.

func NativeWorktreeRemove added in v0.30.0

func NativeWorktreeRemove(t *testing.T, f Fixture, path string)

NativeWorktreeRemove unregisters the linked worktree at path.

func NativeWriteTree added in v0.30.0

func NativeWriteTree(t *testing.T, f Fixture) string

NativeWriteTree writes the current index out as a tree and reports its hash, the cheapest fingerprint of an index a test must prove unchanged.

func Stage added in v0.22.0

func Stage(t testing.TB, f Fixture, write map[string]string)

Stage writes the given paths into the fixture's worktree (creating any parent directories) and adds them to the index without committing, so a test can exercise a staged-but-uncommitted index universe distinct from the working tree.

func StageFile added in v0.30.0

func StageFile(t testing.TB, f Fixture, name, content string, mode os.FileMode)

StageFile writes one path with an explicit file mode and stages it, so a fixture can pin an executable bit the index must preserve.

func StageGitlink(t testing.TB, f Fixture, name string)

StageGitlink appends a gitlink (submodule) index entry, which carries no regular file content and so exercises the readers' skip path.

func StageRemoval added in v0.30.0

func StageRemoval(t testing.TB, f Fixture, names ...string)

StageRemoval stages the deletion of tracked paths without committing, so a test can distinguish a staged deletion from a working-tree one.

func StageUnmerged added in v0.30.0

func StageUnmerged(t testing.TB, f Fixture, name string)

StageUnmerged appends a conflicted (stage-2) index entry, so a test can drive the unmerged-index refusal.

func TreeHash added in v0.30.0

func TreeHash(t testing.TB, f Fixture, rev string) string

TreeHash reports the hex tree hash of the commit named by rev.

Types

type Fixture added in v0.30.0

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

Fixture identifies a fixture repository by its root. Both lanes operate on it, and it is the only repository value the package hands out.

func At added in v0.30.0

func At(root string) Fixture

At names an existing repository checkout, including a linked worktree the code under test registered, so fixture operations can be aimed at it.

func InitNativeAt added in v0.30.0

func InitNativeAt(t *testing.T, root string) Fixture

InitNativeAt creates a git repository at root with the default object format, creating root when it does not exist yet.

func InitNativeObjectFormat added in v0.30.0

func InitNativeObjectFormat(t *testing.T, root, format string) Fixture

InitNativeObjectFormat creates a git repository at root with the named object format, skipping the test when the installed Git cannot provide it. An empty or "sha1" format uses the installed default. The repository carries the fixture identity locally, so operations the code under test performs can commit without a global configuration.

func InitRepo

func InitRepo(t testing.TB) Fixture

InitRepo creates a fresh git repository in a new t.TempDir().

func InitRepoAt added in v0.30.0

func InitRepoAt(t testing.TB, root string) Fixture

InitRepoAt creates a git repository in root, which may already hold files a test wrote before the repository existed.

func (Fixture) Root added in v0.30.0

func (f Fixture) Root() string

Root reports the fixture repository's working-tree root.

Jump to

Keyboard shortcuts

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