git

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package git centralises awf's go-git repository access: opening a repository tolerantly (linked worktrees, submodules, a stray worktreeConfig extension) so every awf command that reads git shares one open path. It reads only; it never mutates a repository.

Index

Constants

This section is empty.

Variables

View Source
var ErrIndexBlob = errors.New("read index blob")

ErrIndexBlob reports a stage-0 regular-file entry whose content cannot be read from the object store.

View Source
var ErrIndexUnmerged = errors.New("index contains unmerged entries")

ErrIndexUnmerged reports an index that has multiple merge stages and cannot represent one deterministic pre-commit snapshot.

Functions

func ChangedPaths

func ChangedPaths(repoRoot string, staged bool, rangeSpec string) ([]string, error)

ChangedPaths returns the sorted, unique repo-relative paths changed either in the staged index (staged) or between the two revisions of rangeSpec ("a..b"). staged takes precedence; with neither selector the caller should not call this. A malformed range or an unresolvable revision is a clear error. It reads the repository only.

func HeadAndClean added in v0.18.0

func HeadAndClean(repoRoot string) (string, error)

HeadAndClean returns the HEAD commit hash and refuses any repository whose working tree is not pristine: a staged, unstaged, untracked, or conflicted entry, or an unborn HEAD (no commit yet), each fails. It is the read-only snapshot-identity seam attestation pins before it mutates the tree, so a recorded PreparedHead unambiguously identifies the pre-mutation commit. It reads the repository only.

func OpenRepo

func OpenRepo(repoRoot string) (*gogit.Repository, error)

OpenRepo opens the repo at repoRoot like git.PlainOpen, but hides its [extensions] config section from go-git's own extension-support check (repository_extensions.go verifyExtensions). That check has an upstream bug: it lowercases the incoming extension name ("worktreeconfig") before comparing it against its allow-list, whose key is mixed-case ("worktreeConfig") - the lookup never matches, so PlainOpen rejects any repo with `extensions.worktreeConfig` set (a flag `git worktree add` can leave behind even after the worktree is removed) regardless of repositoryformatversion. awf's git-reading commands never read repo extensions, so hiding the section is safe.

Unlike git.PlainOpen with default options, this also resolves a `.git` *file* - the `gitdir:` pointer `git worktree add` leaves at a linked worktree's root (and the submodule layout) - mirroring what PlainOpenWithOptions' EnableDotGitCommonDir does, so awf's git-reading commands work from a linked worktree. The manual storage construction (over PlainOpenWithOptions) exists solely so the storer wrapper above can be injected.

func ParseRange added in v0.18.0

func ParseRange(arg string, allowBareBase bool) (base, head string, err error)

ParseRange resolves a range argument to an explicit base and head revision. An argument containing ".." is a two-sided range; otherwise it is a base and head defaults to HEAD, which callers opt into via allowBareBase (ADR-0127 Decision 5). Git forbids ".." inside a ref name, so the discrimination is unambiguous. Rejects an empty side, a three-dot range, a multi-".." input, and a "-"-prefixed side: the first three would reach git as a bogus revision and the last as an option-like argument. Dots inside a revision (v0.10.0) are legal, since git forbids "."-leading, ".."-containing, and "-"-leading refs.

func TrackedPaths added in v0.18.0

func TrackedPaths(repoRoot string) ([]string, error)

TrackedPaths returns the sorted, unique repo-relative slash paths tracked at HEAD. It reads the repository only.

func WorkingPaths added in v0.18.0

func WorkingPaths(repoRoot string) ([]string, error)

WorkingPaths returns tracked HEAD paths that still exist plus nonignored untracked paths. Deleted, ignored, and nested-repository files are excluded by go-git's worktree status semantics.

Types

type HeadBlob added in v0.18.0

type HeadBlob struct {
	Path  string
	Bytes []byte
	Mode  uint32
}

HeadBlob is one ordinary or executable file from the committed HEAD tree.

func HeadBlobsUnder added in v0.18.0

func HeadBlobsUnder(repoRoot, prefix string) ([]HeadBlob, error)

HeadBlobsUnder returns sorted regular HEAD blobs below prefix. It is the read-only snapshot seam used by cross-schema bridge validation.

type IndexBlob added in v0.18.0

type IndexBlob struct {
	Path  string
	Bytes []byte
}

IndexBlob is one regular file's exact bytes from the stage-0 index snapshot.

func IndexBlobs added in v0.18.0

func IndexBlobs(repoRoot string) ([]IndexBlob, error)

IndexBlobs returns sorted stage-0 ordinary and executable blobs from the index. Symlinks and gitlinks have no regular-file content to scan and are ignored. An unmerged or unreadable regular entry makes the snapshot unsafe.

Jump to

Keyboard shortcuts

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