git

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

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 struct {
	Path    string
	OldPath string
	Status  Status
}

type Driver

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

func New

func New() (*Driver, error)

func (*Driver) BaseRef

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

BaseRef finds the merge base against the repo's main branch 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 origin/HEAD and the bare origin ref 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) 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)

IndexFile reads a file's staged content.

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) ResolveRef added in v0.6.0

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

ResolveRef reports whether ref names a commit reachable in root.

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 struct {
	Adds, Dels int
	Binary     bool
}

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 struct {
	Root     string
	Branch   string
	Unborn   bool
	Detached bool
}

type Scope

type Scope int
const (
	ScopeUncommitted Scope = iota
	ScopeBranch
	ScopeLastCommit
	ScopeStaged
)

func (Scope) Next

func (s Scope) Next() Scope

func (Scope) String

func (s Scope) String() string

type Status

type Status byte
const (
	Added     Status = 'A'
	Modified  Status = 'M'
	Deleted   Status = 'D'
	Renamed   Status = 'R'
	Copied    Status = 'C'
	Untracked Status = '?'
	Unmerged  Status = 'U'
)

type Worktree added in v0.6.0

type Worktree struct {
	Root   string
	Branch string
}

Jump to

Keyboard shortcuts

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