Documentation
¶
Overview ¶
Package vcs is the version-control seam: the small set of git operations the harness needs — inspect the working tree, branch, and commit. Git is the adapter over go-git (v6); Mock is an in-memory implementation with the same methods, so a consumer declares a point-of-use interface and swaps them (no unused interface lives here). Errors from go-git are translated to adh.Error at this boundary, so callers see domain codes, not library types. Revert is path-scoped and hermetic (go-git only). Merge is intentionally absent: go-git's merge is experimental, so it remains a `git` shell-out follow-up (TODO).
Index ¶
- type Git
- func (g *Git) Commit(msg string, who Signature, when time.Time) (string, error)
- func (g *Git) CreateBranch(name string) error
- func (g *Git) CurrentBranch() (string, error)
- func (g *Git) Diff(paths []string) (string, error)
- func (g *Git) HeadSHA() (string, error)
- func (g *Git) Revert(paths []string) error
- func (g *Git) Status() (Status, error)
- type Mock
- func (m *Mock) Commit(_ string, _ Signature, _ time.Time) (string, error)
- func (m *Mock) CreateBranch(name string) error
- func (m *Mock) CurrentBranch() (string, error)
- func (m *Mock) Diff(_ []string) (string, error)
- func (m *Mock) HeadSHA() (string, error)
- func (m *Mock) Revert(paths []string) error
- func (m *Mock) Status() (Status, error)
- type Signature
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git is a working repository backed by go-git. Commit takes the author time from the caller so the adapter reads no clock (the shell owns it).
func (*Git) Commit ¶
Commit stages every change in the working tree (git add -A) and records a commit authored by who at when, returning the short hash.
func (*Git) CreateBranch ¶
CreateBranch creates a branch at HEAD and checks it out. It requires at least one commit, since a branch points at a commit.
func (*Git) CurrentBranch ¶
CurrentBranch returns the checked-out branch. Before the first commit HEAD has no target commit, so it falls back to the symbolic HEAD's branch name.
func (*Git) Diff ¶
Diff renders a unified diff of the given repository-relative paths between the committed HEAD content and the current working tree — the pre-commit change under review (SPEC-ADDITIONS §19.1). It reads both sides through the go-git handle and formats the text with gotextdiff, so it needs no `git` binary. A path unchanged between HEAD and the tree contributes nothing; a path absent from HEAD reads as all-added, one absent from the tree as all-removed.
func (*Git) HeadSHA ¶
HeadSHA returns the full commit hash at HEAD, for recording proof provenance (SPEC §5.4). Before the first commit there is no commit to name, so it returns "" (not an error) — provenance is simply absent.
func (*Git) Revert ¶
Revert restores the given repository-relative paths to their committed HEAD state, discarding uncommitted work under them (SPEC §2.3 reject/revert). A path tracked in HEAD is rewritten to its committed content; a path new to HEAD is removed from the working tree. It is scoped to the given paths — never touching anything outside them (so the .adh workspace and unrelated work are safe) — and hermetic (go-git only, no `git` binary).
type Mock ¶
type Mock struct {
Branch string
Changed []string
Patch string // scripted Diff output
SHA string // scripted HeadSHA output
// contains filtered or unexported fields
}
Mock is an in-memory Repo for tests and consumers that need no real repository. Branch and Changed are scripted; Commit clears Changed, marks the tree clean, and returns a deterministic hash derived from a monotonic counter.
func (*Mock) Commit ¶
Commit clears the changed set and returns a deterministic fake hash. It ignores who and when so callers stay clock-free and tests stay stable.
func (*Mock) CreateBranch ¶
CreateBranch switches the scripted branch.
func (*Mock) CurrentBranch ¶
CurrentBranch returns the scripted branch, defaulting to "main".
func (*Mock) Diff ¶
Diff returns the scripted patch. It ignores paths — the mock has no tree to diff — so a test sets Patch to whatever the consumer should see.
func (*Mock) HeadSHA ¶
HeadSHA returns the scripted commit SHA (empty by default, mirroring a repo with no commit yet).