Help us shape the future of Go! Take the 2026 Go Developer Survey

vcs

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 15 Imported by: 0

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

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 Init

func Init(dir string) (*Git, error)

Init creates a new, empty repository at dir.

func Open

func Open(dir string) (*Git, error)

Open opens an existing repository rooted at dir.

func (*Git) Commit

func (g *Git) Commit(msg string, who Signature, when time.Time) (string, error)

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

func (g *Git) CreateBranch(name string) error

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

func (g *Git) CurrentBranch() (string, error)

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

func (g *Git) Diff(paths []string) (string, error)

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

func (g *Git) HeadSHA() (string, error)

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

func (g *Git) Revert(paths []string) error

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).

func (*Git) Status

func (g *Git) Status() (Status, error)

Status reports the branch, cleanliness, and changed paths of the working tree.

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

func (m *Mock) Commit(_ string, _ Signature, _ time.Time) (string, error)

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

func (m *Mock) CreateBranch(name string) error

CreateBranch switches the scripted branch.

func (*Mock) CurrentBranch

func (m *Mock) CurrentBranch() (string, error)

CurrentBranch returns the scripted branch, defaulting to "main".

func (*Mock) Diff

func (m *Mock) Diff(_ []string) (string, error)

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

func (m *Mock) HeadSHA() (string, error)

HeadSHA returns the scripted commit SHA (empty by default, mirroring a repo with no commit yet).

func (*Mock) Revert

func (m *Mock) Revert(paths []string) error

Revert drops the given paths from the scripted changed set, mirroring a revert of their working-tree changes. Paths not in the set are ignored.

func (*Mock) Status

func (m *Mock) Status() (Status, error)

Status reports the scripted branch and changed set; clean when Changed empty.

type Signature

type Signature struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

Signature is a commit author.

type Status

type Status struct {
	Branch  string   `json:"branch"`
	Clean   bool     `json:"clean"`
	Changed []string `json:"changed"`
}

Status is a snapshot of the working tree: the current branch, whether it is clean, and the sorted set of changed (staged, modified, or untracked) paths.

Jump to

Keyboard shortcuts

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