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

git

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package git shells out to the git CLI to read diff data for a repo.

Index

Constants

View Source
const (
	ScopeUncommitted = value.ScopeUncommitted
	ScopeBranch      = value.ScopeBranch
	ScopeLastCommit  = value.ScopeLastCommit
	ScopeStaged      = value.ScopeStaged
)
View Source
const (
	Added     = value.Added
	Modified  = value.Modified
	Deleted   = value.Deleted
	Renamed   = value.Renamed
	Copied    = value.Copied
	Untracked = value.Untracked
	Unmerged  = value.Unmerged
)

Variables

View Source
var ErrNotARepo = errors.New("not a git repository")

Functions

func IsBinary

func IsBinary(content []byte) bool

IsBinary sniffs for a NUL byte in the first 8 KiB.

Types

type ChangedFile

type ChangedFile = value.ChangedFile

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

func New

func New() (*Driver, error)

func (*Driver) AddWorktree added in v0.15.0

func (d *Driver) AddWorktree(root, sessionName, baseOverride string) (string, string, error)

func (*Driver) BaseRef

func (d *Driver) BaseRef(root string) (ref, describe string, err error)

BaseRef finds the merge base against the repo's default base for the branch scope, returning the resolved ref and a short description.

func (*Driver) BranchBase added in v0.6.0

func (d *Driver) BranchBase(root, override string) (ref, describe string, err error)

BranchBase resolves the base ref the branch scope diffs against. A non-empty override is validated first and fails loudly when it no longer resolves, never falling back to auto-detection; empty override auto-detects.

func (*Driver) BranchRefs added in v0.6.0

func (d *Driver) BranchRefs(root string) ([]string, error)

BranchRefs lists local and remote branch short names, dropping the symbolic refs such as origin/HEAD that name a remote's default rather than a branch.

func (*Driver) ChangedFiles

func (d *Driver) ChangedFiles(root string, scope Scope, baseRef string) ([]ChangedFile, error)

func (*Driver) CountWorkingLines added in v0.6.0

func (d *Driver) CountWorkingLines(root, path string) (LineCount, error)

CountWorkingLines streams a working-tree file, so files too big to diff still count.

func (*Driver) DefaultBase added in v0.40.0

func (d *Driver) DefaultBase(dir string) string

DefaultBase is the branch work in the repo merges into: the default branch on upstream, which GitHub's fork layout names the parent, else on origin, else the local branch. "" when the repo names no default branch.

func (*Driver) FetchBase added in v0.40.0

func (d *Driver) FetchBase(dir, override string) error

FetchBase updates the remote-tracking branch a worktree would branch from, and only that branch, so a session starts from the remote's tip rather than from whatever the last fetch left behind.

func (*Driver) Fingerprint

func (d *Driver) Fingerprint(root string, scope Scope, baseRef string) (uint64, error)

Fingerprint hashes the repo state visible to a scope so callers can cheaply detect when a reload is needed.

func (*Driver) IndexFile

func (d *Driver) IndexFile(root, path string) ([]byte, error)

func (*Driver) IsRepoRoot added in v0.6.0

func (d *Driver) IsRepoRoot(dir string) bool

func (*Driver) LastCommitParent added in v0.9.1

func (d *Driver) LastCommitParent(root string) string

LastCommitParent returns HEAD's parent ref, or git's empty-tree object when HEAD is a root commit.

func (*Driver) NumStat

func (d *Driver) NumStat(root string, scope Scope, baseRef string) (map[string]FileStat, error)

func (*Driver) OpenRepo

func (d *Driver) OpenRepo(dir string) (Repo, error)

func (*Driver) RemoveWorktreeIfClean added in v0.15.0

func (d *Driver) RemoveWorktreeIfClean(root, path, branch, baseOverride string) (bool, error)

RemoveWorktreeIfClean removes a session's worktree and its am/ branch only when nothing would be lost: no uncommitted or untracked files, and no commits that exist nowhere else. A kept worktree is not an error.

func (*Driver) RenameWorktreeBranch added in v0.35.0

func (d *Driver) RenameWorktreeBranch(root, path, branch, newName string) (string, error)

RenameWorktreeBranch gives a managed worktree the branch a session of newName would have received at spawn without moving its live directory. The recorded branch is returned untouched when the worktree directory or branch no longer exists, or the worktree has left the recorded branch (switched to another, or detached mid-rebase), which is what a worktree renamed, removed or repointed by hand looks like.

func (*Driver) RepoRoot added in v0.15.0

func (d *Driver) RepoRoot(dir string) (string, error)

func (*Driver) ResolveRef added in v0.6.0

func (d *Driver) ResolveRef(root, ref string) error

func (*Driver) ResolveRepos added in v0.5.0

func (d *Driver) ResolveRepos(cwd string) ([]string, error)

ResolveRepos returns the git repo roots reachable from cwd, most-active first. When cwd is itself a repo, that repo plus its linked worktrees are the roots. When cwd is an umbrella folder holding several repos, each nested repo root is returned ranked with dirty working trees before clean ones, then by most recent commit, so review lands on the repo the agent is most likely editing.

func (*Driver) ShowFile

func (d *Driver) ShowFile(root, ref, path string) ([]byte, error)

ShowFile reads a file's content at a ref; a path absent at the ref returns empty content (the file was added since).

func (*Driver) WorkingFile

func (d *Driver) WorkingFile(root, path string) ([]byte, error)

func (*Driver) Worktrees added in v0.6.0

func (d *Driver) Worktrees(root string) ([]Worktree, error)

type FileStat

type FileStat = value.FileStat

type LineCount added in v0.6.0

type LineCount struct {
	Lines   int
	Binary  bool
	Counted bool
}

LineCount reports a file's lines; Counted is false when it could not be scanned.

type Repo

type Repo = value.Repo

type Scope

type Scope = value.Scope

type Status

type Status = value.Status

type Worktree added in v0.6.0

type Worktree = value.Worktree

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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