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 ¶
- Variables
- func ChangedPaths(repoRoot string, staged bool, rangeSpec string) ([]string, error)
- func GlobalExcludePatterns() []gitignore.Pattern
- func HeadExists(repoRoot string) (bool, error)
- func HeadHash(repoRoot string) (string, error)
- func OpenContainingRepo(projectRoot string) (*gogit.Repository, string, error)
- func OpenRepo(repoRoot string) (*gogit.Repository, error)
- func ParseRange(arg string, allowBareBase bool) (base, head string, err error)
- func WorkingPaths(repoRoot string) ([]string, error)
- type BlobMode
- type IndexBlob
Constants ¶
This section is empty.
Variables ¶
var ErrIndexBlob = errors.New("read index blob")
ErrIndexBlob reports a stage-0 regular-file entry whose content cannot be read from the object store.
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 ¶
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 GlobalExcludePatterns ¶ added in v0.22.0
GlobalExcludePatterns returns the ignore patterns git applies from outside the repository: core.excludesfile from the system /etc/gitconfig and from the user's ~/.gitconfig. go-git's worktree status consults only the repo's own .gitignore chain and .git/info/exclude, so a status-based path universe that consumes untracked entries must inject these itself to mirror `git status`. Global patterns follow system patterns so the user's rules win where they conflict, matching git's precedence; the ordering is exercised only against the real root filesystem because LoadSystemPatterns hardcodes /etc/gitconfig. One narrow divergence from git remains, shared with the audit rule this helper was extracted from: go-git composes Excludes after the repo's .gitignore chain, so a repo-level negation cannot re-include a globally-ignored file. Absent or unreadable sources contribute no patterns: the callers read repository state, and a missing optional ignore source must not fail them.
func HeadExists ¶ added in v0.22.0
HeadExists reports whether the repository has a born HEAD (at least one commit). A fresh repository whose immediate symbolic HEAD target is absent reports false without error. Missing refs deeper in a symbolic chain and corrupt or cyclic chains are errors. It reads the repository only.
func HeadHash ¶ added in v0.22.0
HeadHash resolves the current HEAD commit hash without requiring a clean working tree. The final current-state upgrade runs in an integration worktree that carries the applied but uncommitted attestation patches, so it compares HEAD identity against the sealed PreparedHead without a cleanliness check.
func OpenContainingRepo ¶ added in v0.22.0
func OpenContainingRepo(projectRoot string) (*gogit.Repository, string, error)
OpenContainingRepo opens the Git repository containing projectRoot and returns the repository-relative slash-separated prefix of projectRoot. The prefix is empty when projectRoot itself is the repository root.
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
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 WorkingPaths ¶ added in v0.18.0
WorkingPaths returns tracked HEAD paths that still exist plus nonignored untracked paths, rerooted to repoRoot. A specifically unborn HEAD supplies an empty committed baseline; every other repository, reference, or object error still fails. repoRoot may be an adopted project nested inside a containing monorepo; paths outside that project are excluded. Deleted and nested-repository files are excluded by go-git's worktree status semantics; ignored files are excluded by those semantics plus the injected global and system excludes (GlobalExcludePatterns).
Types ¶
type BlobMode ¶ added in v0.22.0
type BlobMode uint8
BlobMode is the closed set of Git blob modes preserved by snapshots.
type IndexBlob ¶ added in v0.18.0
IndexBlob is one file's exact bytes and mode from a stage-0 index or a resolved commit tree. Symlink bytes are the inert link target.
func CommitBlobs ¶ added in v0.22.0
CommitBlobs returns the sorted regular and executable blobs of the tree that rev resolves to. Symlinks and gitlinks carry no regular-file content to scan and are skipped. It reads the repository only.
func IndexBlobs ¶ added in v0.18.0
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.
func RangeBlobs ¶ added in v0.22.0
RangeBlobs returns the before/after regular-blob sets for the transition into the commit rev resolves to: after is that commit's tree, before is its first-parent tree, or nil for a root commit. Merges follow the first parent only, so an ADR status change committed on a branch and merged is still observed at the merge. It reads the repository only.