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 ¶
- Variables
- func Add(t testing.TB, f Fixture, paths ...string)
- func AddAll(t testing.TB, f Fixture)
- func CheckoutNewBranch(t testing.TB, f Fixture, name, at string)
- func Commit(t testing.TB, f Fixture, msg string, write map[string]string, remove ...string) string
- func Graft(t testing.TB, f Fixture, msg, treeFrom string, parents ...string) string
- func Merge(t testing.TB, f Fixture, msg string, parents ...string) string
- func NativeAdd(t *testing.T, f Fixture, paths ...string)
- func NativeAddAllExcept(t *testing.T, f Fixture, exclude ...string)
- func NativeAnnotatedTag(t *testing.T, f Fixture, name, target string)
- func NativeBranch(t *testing.T, f Fixture, name string)
- func NativeBranchForce(t *testing.T, f Fixture, name, target string)
- func NativeCatFile(t *testing.T, f Fixture, objectType, rev string) []byte
- func NativeCheckout(t *testing.T, f Fixture, ref string)
- func NativeCheckoutNewBranch(t *testing.T, f Fixture, name, target string)
- func NativeCheckoutOrphan(t *testing.T, f Fixture, name string)
- func NativeCommit(t *testing.T, f Fixture, msg string)
- func NativeCommitAllowEmpty(t *testing.T, f Fixture, msg string) string
- func NativeConfig(t *testing.T, f Fixture, key, value string)
- func NativeGitPath(t *testing.T, f Fixture, name string) string
- func NativeHashObject(t *testing.T, f Fixture, objectType string, body []byte) string
- func NativeLightweightTag(t *testing.T, f Fixture, name, target string)
- func NativeMergeAbort(t *testing.T, f Fixture)
- func NativeRemoveAll(t *testing.T, f Fixture)
- func NativeRevParse(t *testing.T, f Fixture, rev string) string
- func NativeRevisionExists(t *testing.T, f Fixture, rev string) bool
- func NativeRun(f Fixture, args ...string) (string, error)
- func NativeSSHKey(t *testing.T) (string, string)
- func NativeSignedCommit(t *testing.T, f Fixture, msg, privateKey string) string
- func NativeSignedCommitAs(t *testing.T, f Fixture, msg, privateKey, name, email string) string
- func NativeUpdateRef(t *testing.T, f Fixture, ref, target string)
- func NativeWorktreeAdd(t *testing.T, f Fixture, path, branch string)
- func NativeWorktreeAddDetached(t *testing.T, f Fixture, path, rev string)
- func NativeWorktreeRemove(t *testing.T, f Fixture, path string)
- func NativeWriteTree(t *testing.T, f Fixture) string
- func Stage(t testing.TB, f Fixture, write map[string]string)
- func StageFile(t testing.TB, f Fixture, name, content string, mode os.FileMode)
- func StageGitlink(t testing.TB, f Fixture, name string)
- func StageRemoval(t testing.TB, f Fixture, names ...string)
- func StageUnmerged(t testing.TB, f Fixture, name string)
- func TreeHash(t testing.TB, f Fixture, rev string) string
- type Fixture
Constants ¶
This section is empty.
Variables ¶
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
Add stages paths that already exist in the worktree, including a symlink the test created itself.
func AddAll ¶ added in v0.30.0
AddAll stages every change in the worktree, matching `git add -A` at the repository root.
func CheckoutNewBranch ¶ added in v0.30.0
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 ¶
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
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
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 NativeAddAllExcept ¶ added in v0.30.0
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
NativeAnnotatedTag creates an annotated tag at target.
func NativeBranch ¶ added in v0.30.0
NativeBranch creates a branch at HEAD.
func NativeBranchForce ¶ added in v0.30.0
NativeBranchForce points a branch at target, creating or moving it.
func NativeCatFile ¶ added in v0.30.0
NativeCatFile returns the exact bytes of one object.
func NativeCheckout ¶ added in v0.30.0
NativeCheckout checks out an existing reference.
func NativeCheckoutNewBranch ¶ added in v0.30.0
NativeCheckoutNewBranch creates and checks out a branch at target.
func NativeCheckoutOrphan ¶ added in v0.30.0
NativeCheckoutOrphan starts an orphan branch, the parentless history go-git cannot check out.
func NativeCommit ¶ added in v0.30.0
NativeCommit commits the staged tree with the fixture identity.
func NativeCommitAllowEmpty ¶ added in v0.30.0
NativeCommitAllowEmpty creates an unsigned commit with the fixture identity.
func NativeConfig ¶ added in v0.30.0
NativeConfig sets a repository-local configuration value in a disposable fixture.
func NativeGitPath ¶ added in v0.30.0
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
NativeHashObject writes exact object bytes and returns the new object ID.
func NativeLightweightTag ¶ added in v0.30.0
NativeLightweightTag creates a lightweight tag at target.
func NativeMergeAbort ¶ added in v0.30.0
NativeMergeAbort abandons an in-progress merge.
func NativeRemoveAll ¶ added in v0.30.0
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
NativeRevParse resolves a revision to its hex object id.
func NativeRevisionExists ¶ added in v0.30.0
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
NativeRun executes Git in a disposable fixture and returns combined output and the exact process error.
func NativeSSHKey ¶ added in v0.30.0
NativeSSHKey generates one passwordless Ed25519 signing key and returns its private path and option-free public record.
func NativeSignedCommit ¶ added in v0.30.0
NativeSignedCommit creates one genuinely SSH-signed commit with the fixture identity.
func NativeSignedCommitAs ¶ added in v0.30.0
NativeSignedCommitAs creates one genuinely SSH-signed commit with an exact identity.
func NativeUpdateRef ¶ added in v0.30.0
NativeUpdateRef points one exact reference at an existing object ID.
func NativeWorktreeAdd ¶ added in v0.30.0
NativeWorktreeAdd registers a linked worktree at path on a new branch.
func NativeWorktreeAddDetached ¶ added in v0.30.0
NativeWorktreeAddDetached registers a linked worktree at path with a detached HEAD at rev.
func NativeWorktreeRemove ¶ added in v0.30.0
NativeWorktreeRemove unregisters the linked worktree at path.
func NativeWriteTree ¶ added in v0.30.0
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
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
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 ¶ added in v0.30.0
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
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
StageUnmerged appends a conflicted (stage-2) index entry, so a test can drive the unmerged-index refusal.
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
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
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
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 InitRepoAt ¶ added in v0.30.0
InitRepoAt creates a git repository in root, which may already hold files a test wrote before the repository existed.