gitx

package
v0.2.2-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitx reads and manipulates git repositories for the sidebar: repository discovery, worktrees, branches, status and diffs. Everything shells out to the git binary.

Index

Constants

View Source
const (
	RewriteSame    = "same"    // the same change on a new parent
	RewriteChanged = "changed" // its change is different: a conflict was resolved in it
	RewriteDropped = "dropped" // gone: the base had it already, or it was left out
	RewriteAdded   = "added"   // new in the rewrite
)

How a commit came through a rebase.

Variables

View Source
var ErrEmptyBundle = errors.New("gitx: nothing to bundle")

ErrEmptyBundle means the other repository already has every commit.

View Source
var ErrNoBranch = errors.New("no such branch")

ErrNoBranch is Unmerged's answer for a branch that is not there: nothing to lose, and nothing to delete either.

View Source
var ErrNoCommits = errors.New("the repository has no commits yet")

ErrNoCommits is a repository with no commits: there is nothing for a bundle to carry.

View Source
var ErrNoMergeTree = errors.New("this git cannot try a merge without making it (git 2.38 or later can)")

ErrNoMergeTree says git is too old to try a merge without making it (merge-tree --write-tree arrived in git 2.38).

View Source
var ErrNotRepo = errors.New("gitx: not a git repository")

ErrNotRepo is returned by Discover when a directory is not inside a git work tree.

View Source
var ErrNothingToCommit = errors.New("nothing to commit")

ErrNothingToCommit is returned by CommitChanges when there are no changes.

View Source
var ErrPatchStale = errors.New("the files changed since the diff was read")

ErrPatchStale is returned when a patch no longer applies: the file changed after the diff it was cut from was read.

Functions

func AddWorktree

func AddWorktree(ctx context.Context, root, path, branch, base string) error

AddWorktree checks out branch at path, creating the branch from base when it does not exist locally.

func Ahead added in v0.1.1

func Ahead(ctx context.Context, root, branch, base string) int

Ahead counts the commits branch has that base lacks.

func ApplyPatch added in v0.1.4

func ApplyPatch(ctx context.Context, dir string, patch []byte, index bool) error

ApplyPatch applies a patch from WorkPatches in the checkout at dir, to the index as well with index. An empty patch does nothing.

func AttemptBase added in v0.1.1

func AttemptBase(branch string) string

AttemptBase is the task a branch is an attempt at, or "" when it is not one: the part before the last component of AttemptBranch.

func AttemptBranch added in v0.1.1

func AttemptBranch(base, agent string, n int, taken func(string) bool) string

AttemptBranch names one attempt at the same task: the base branch, then the agent that tries it, so several attempts sort together under the base and read plainly in the tree:

conch/fix-flaky-test/claude
conch/fix-flaky-test/codex
conch/fix-flaky-test/claude-2   (the same agent, twice)

n counts from 1; taken says which names are already in use.

func BaseChanges added in v0.1.9

func BaseChanges(ctx context.Context, dir, branch, base string, files []string, n int) string

BaseChanges is what base did to files since branch left it, newest first and at most n commits: the other side of a conflict, for whoever resolves it.

func BranchFromPrompt

func BranchFromPrompt(project, prompt string) string

BranchFromPrompt derives a branch name from an agent prompt, under the project's own name, e.g. in a project called OneNutri "Fix the flaky login tests!" -> "onenutri/fix-flaky-login-tests". Branches conch makes are grouped that way in every project; without a project name they fall back to "conch/".

func BranchHead added in v0.1.1

func BranchHead(ctx context.Context, root, branch string) (string, error)

BranchHead returns the commit a local branch points at.

func BranchPrefix added in v0.1.3

func BranchPrefix(project string) string

BranchPrefix is what conch puts task branches under in a project: its name, slugged, ending in "/".

func BundleAll added in v0.2.0

func BundleAll(ctx context.Context, root, file string) error

BundleAll writes every branch and tag of the repository at root to file, for a machine that cannot clone it from anywhere.

func Changed added in v0.1.9

func Changed(ctx context.Context, dir, base string) ([]string, error)

Changed lists the files the checkout's HEAD has changed since it left base, sorted.

func ChangedAt added in v0.1.9

func ChangedAt(ctx context.Context, dir, base, rev string) ([]string, error)

ChangedAt is Changed for rev rather than the checkout's HEAD.

func CheckUserCommand added in v0.1.6

func CheckUserCommand(args []string) error

CheckUserCommand refuses what the git panel must not run. A command starts with a subcommand: git's own options before it (-C, -c, --git-dir, --exec-path) would point it at another repository or at another program.

func CheckoutDetached added in v0.2.1

func CheckoutDetached(ctx context.Context, root, path, ref string) error

CheckoutDetached puts a worktree of root at path on ref, detached — no branch, so nothing finished there looks like work to ship — making it the first time and moving it after. Anything changed in it is thrown away: it is a place to read the code at ref, nothing more.

func Clone added in v0.1.4

func Clone(ctx context.Context, url, dir string) error

Clone clones url into dir, which must not exist yet or be empty. It never waits for a password: a server has no one to type it.

func CommitChanges added in v0.1.1

func CommitChanges(ctx context.Context, dir, message string, files []string) (string, error)

CommitChanges commits the changes in the checkout at dir with message and returns the new commit's hash. With files empty every change is committed, untracked files included; otherwise only those paths are (a rename needs both its old and new path), and anything else already staged stays staged.

func CommitFileDiff added in v0.1.9

func CommitFileDiff(ctx context.Context, dir, from, to, path string) (string, error)

CommitFileDiff is one file's diff in a commit, or between two commits when from is given.

func CommitOf added in v0.1.9

func CommitOf(ctx context.Context, dir, rev string) string

CommitOf is the commit rev names in dir now, or "" when it names none: a ref read once, so what it meant then is kept when the ref moves on.

func CommitPatchChanges added in v0.1.1

func CommitPatchChanges(ctx context.Context, dir, message, patch string, files []string) (string, error)

CommitPatchChanges stages patch (a unified diff, as from Diff) and every path in files, then commits what is staged — anything staged beforehand included, as git itself would. A patch that no longer applies changes nothing and returns ErrPatchStale.

func CommitStaged added in v0.1.9

func CommitStaged(ctx context.Context, dir, message string) (string, error)

CommitStaged commits what is in the index and nothing else, as git commit does; ErrNothingToCommit when nothing is staged.

func ConflictFiles added in v0.2.1

func ConflictFiles(ctx context.Context, dir string) []string

ConflictFiles are the files a merge or rebase stopped on in the checkout at dir: those git lists as unmerged.

func CreateBundle added in v0.1.4

func CreateBundle(ctx context.Context, dir, file, branch, have string) error

CreateBundle writes the commits of branch that have doesn't reach to a bundle at file. With have "" the whole history goes.

func DefaultBase

func DefaultBase(ctx context.Context, root string) string

DefaultBase guesses the branch new work should start from.

func DeleteBranch added in v0.1.1

func DeleteBranch(ctx context.Context, root, branch string) error

DeleteBranch deletes a local branch, merged or not.

func DeleteRef added in v0.1.4

func DeleteRef(ctx context.Context, root, ref string)

DeleteRef removes a ref such as the one FetchBundle wrote.

func Deleted added in v0.1.9

func Deleted(ctx context.Context, dir, base string) ([]string, error)

Deleted lists the files the checkout's HEAD has deleted since it left base, sorted: what a rewrite of the branch must not add to.

func Diff

func Diff(ctx context.Context, dir, file, rev string) (string, error)

Diff returns a unified diff of file in dir. With rev empty it shows the working tree and index against HEAD (untracked files diff against /dev/null); otherwise it is `git diff <rev> -- file`, e.g. "main...feat".

func DiffSize added in v0.1.9

func DiffSize(ctx context.Context, dir, base string) (int, error)

DiffSize is how many lines the checkout's HEAD adds and removes since it left base, together: the size of the pull request it would make.

func DiffSizeAt added in v0.1.9

func DiffSizeAt(ctx context.Context, dir, base, rev string) (int, error)

DiffSizeAt is DiffSize for rev rather than the checkout's HEAD.

func FetchBundle added in v0.1.4

func FetchBundle(ctx context.Context, root, file, branch, ref string) (string, error)

FetchBundle takes branch's commits from a bundle into the repository at root under ref, which it may overwrite, and returns the commit.

func Files added in v0.1.9

func Files(ctx context.Context, dir string) ([]string, error)

Files is every file of the checkout at dir that git knows or would add: tracked ones and untracked ones it does not ignore, relative to dir, with slashes. A file deleted but not yet committed is left out.

func ForceRemoveWorktree added in v0.1.1

func ForceRemoveWorktree(ctx context.Context, root, path string) error

ForceRemoveWorktree removes the linked worktree at path, discarding its uncommitted changes.

func FreshBase added in v0.1.9

func FreshBase(ctx context.Context, dir, branch, base string) string

FreshBase fetches base from the remote the branch would push to and names it as the remote has it ("origin/main"). Without a remote, or one that has no such branch, it is base as this checkout has it.

func HaveCommits added in v0.1.4

func HaveCommits(ctx context.Context, dir string, list []string) ([]string, error)

HaveCommits returns the commits of list that exist in the repository at dir, in list's order. Anything that isn't a full hash is left out.

func History added in v0.1.4

func History(ctx context.Context, dir, rev string, n int) ([]string, error)

History lists up to n commits of rev's first-parent line, newest first: the candidates another repository may already have.

func IgnoredDirs added in v0.1.3

func IgnoredDirs(ctx context.Context, dir string) ([]string, error)

IgnoredDirs lists the directories in the checkout at dir that git ignores whole, relative to dir and slash-separated with no trailing slash. It is what a file watcher must not descend into: one entry stands for the whole of node_modules or target, so the answer stays small however large they are.

Ignored files are left out — only directories, which are the ones that cost a watch each.

func IgnoredPaths added in v0.1.4

func IgnoredPaths(ctx context.Context, dir string) ([]string, error)

IgnoredPaths lists what git ignores in the checkout at dir, relative to dir and slash-separated: files as they are, and a wholly ignored directory once, with a trailing slash, rather than everything in it.

func IgnoresDir added in v0.2.0

func IgnoresDir(ctx context.Context, dir, rel string) (bool, error)

IgnoresDir reports whether git ignores the directory rel (relative to the checkout at dir, slash-separated) — as a directory, so a rule like `build/` counts, and whether or not anything is in it yet. IgnoredDirs cannot say this about a folder just made: an empty one is left out of its list.

func InProgress added in v0.1.6

func InProgress(ctx context.Context, dir string) string

InProgress names the operation left unfinished in the checkout at dir — "rebase", "merge", "cherry-pick", "revert" or "am" — or "" when there is none. Each worktree has its own, so a conflict in one doesn't show in the others.

func InitFromBundle added in v0.2.0

func InitFromBundle(ctx context.Context, bundle, dir, branch string) error

InitFromBundle makes dir, which must not exist yet or be empty, a new repository holding every branch and tag of bundle, with branch checked out — or, when it has no such branch, its first. It has no remote: a bundle is not somewhere to fetch from again.

func InitRepo

func InitRepo(ctx context.Context, dir string) error

InitRepo makes dir a git repository on branch main with an empty first commit, so branches and worktrees can be made from it straight away. Files already in dir are left untracked: committing them is the person's call, and a first commit made behind their back could take in a secret. The commit is made with commit-tree, like seedUnborn's, so nothing staged in a repository that already existed is swept into it, and a repository that has commits is left as it was.

Without an author identity there can be no commit, and a repository with none is one no worktree can branch from, so that is an error that says how to fix it, and a .git this call made is taken away again: the folder is left as it was found, and asking again once git has an identity works.

func IsAncestor added in v0.1.4

func IsAncestor(ctx context.Context, dir, a, b string) bool

IsAncestor reports whether a is an ancestor of (or the same as) b.

func Merge added in v0.1.1

func Merge(ctx context.Context, dir, branch string, squash bool, message string) (string, error)

Merge merges branch into the branch checked out at dir, which must have no uncommitted changes to tracked files. With squash the branch's changes become one new commit; otherwise a merge commit is always made. message "" uses git's own. A merge that conflicts is undone and returned as a *ConflictError, so the checkout is left as it was.

func MergeConflicts added in v0.1.9

func MergeConflicts(ctx context.Context, root, into, branch string) ([]string, error)

MergeConflicts tries merging branch into into without touching any checkout, and lists the files that would conflict; none means it would merge cleanly.

func Merged added in v0.1.1

func Merged(ctx context.Context, root, branch, base string) bool

Merged reports whether base, or base's upstream, already has everything on branch: its commits, or their changes (a squash merge).

func MetaStamp

func MetaStamp(commonDir string) string

MetaStamp is a cheap fingerprint of a repository's git metadata, computed from file mtimes and sizes without running git. It changes when refs, HEAD, the index or worktrees change, so callers can skip refreshes otherwise. It reads both ref backends: the files one (refs/heads, packed-refs) and reftable, git 3's default, where every ref — HEAD too — is in reftable/ and the files above never move.

func Operation added in v0.2.1

func Operation(ctx context.Context, dir string) (op, branch string)

Operation is InProgress and, for a rebase, the branch it is rewriting, read with one call to git. The branch is "" for anything but a rebase of a branch: an am also keeps rebase-apply, and a rebase of a detached HEAD writes "detached HEAD" where a branch's name would be.

func OperationWord added in v0.2.1

func OperationWord(op string) string

OperationWord says what Operation found as a person reads it beside a branch: "rebasing" for "rebase".

func OtherFiles added in v0.1.4

func OtherFiles(ctx context.Context, dir string) ([]string, error)

OtherFiles lists the files in the checkout at dir that git doesn't track and doesn't ignore.

func Printable added in v0.2.0

func Printable(s string) string

Printable makes text git keeps as it was written — a subject, an author, a branch name — safe to draw on a terminal. git keeps control characters, so a cloned repository's commit could carry an escape (OSC 52 writes the clipboard, OSC 2 retitles the window) that opening its history would obey. C0 controls, DEL and the C1 range (0x80–0x9f, which a terminal may take as the start of a sequence) become a dot, a tab a space, and bytes that are not UTF-8 (a raw 0x9b, say) U+FFFD.

func PrintableText added in v0.2.0

func PrintableText(s string) string

PrintableText is Printable for a commit's body: its line breaks stay.

func PruneWorktrees added in v0.1.1

func PruneWorktrees(ctx context.Context, root string) error

PruneWorktrees forgets worktrees whose folders are gone.

func Push added in v0.1.1

func Push(ctx context.Context, root, branch string) error

Push pushes branch to the branch of the same name on its upstream's remote, or on origin (or the only remote), and makes that its upstream. An upstream under another name is not pushed to: a task branch started from origin/main tracks origin/main, and pushing there would put the task's commits on main (git's push.default=simple refuses it too). A push the remote is ahead of comes back as a *PushRejectedError, which PushRebase can mend.

func PushOver added in v0.1.9

func PushOver(ctx context.Context, dir, branch, expect string) error

PushOver replaces branch on its remote with the checkout's, but only if the remote still has expect there: anything pushed since is kept, and comes back as a *PushRejectedError rather than being overwritten.

func PushRebase added in v0.1.5

func PushRebase(ctx context.Context, dir, branch string) (took int, err error)

PushRebase takes the commits the remote has on branch, puts the branch's own on top of them and pushes. dir is the worktree the branch is checked out in, since a rebase needs one. It reports how many commits came from the remote. A rebase that conflicts is undone — the branch stays as it was and nothing is pushed — and uncommitted changes to tracked files stop it before it starts, so a rebase never moves work nobody committed.

func PushedHead added in v0.1.9

func PushedHead(ctx context.Context, dir, branch string) string

PushedHead is the commit the remote last had for branch, as this checkout knows it, or "" when it was never pushed.

func RebaseOnto added in v0.1.9

func RebaseOnto(ctx context.Context, dir, branch, onto string) (moved bool, err error)

RebaseOnto puts branch's own commits on top of onto, in dir where it is checked out, and says whether that moved it. Uncommitted changes to tracked files stop it before it starts; one that conflicts is undone and comes back as an *OntoConflictError naming the files.

func RebasingBranch added in v0.1.6

func RebasingBranch(ctx context.Context, dir string) string

RebasingBranch is the branch a rebase in the checkout at dir is rewriting, or "". git detaches HEAD while it works, so the worktree list shows no branch there until the rebase ends.

func RemoteURL added in v0.1.4

func RemoteURL(ctx context.Context, root string) string

RemoteURL is the URL of the repository's origin, or of its only remote; "" when it has neither.

func Remotes added in v0.1.9

func Remotes(ctx context.Context, dir string) []string

Remotes are the names of a repository's remotes (origin, upstream, a fork's), by which a decoration such as fork/main is told to be a remote's branch rather than a local one with a slash in its name.

func RemoveWorktree

func RemoveWorktree(ctx context.Context, root, path string) error

RemoveWorktree removes the linked worktree at path. It never forces, so a dirty worktree is refused with git's error.

func RepoName added in v0.2.0

func RepoName(rawURL string) string

RepoName is the folder a clone of rawURL is given by default — what `git clone` itself names it: the last part of the repository's path, without .git. It reads https and ssh URLs, scp-like ones (git@github.com:owner/repo.git) and local paths, and is "" when the URL names no repository (a host alone, or nothing).

func RewriteDiff added in v0.2.1

func RewriteDiff(ctx context.Context, dir string, r *Rebase, max int) (string, error)

RewriteDiff is git range-diff's account of the rebase: for each commit that changed, the diff of its diff — what resolving the conflict did. Longer than max (when max > 0) and it is cut there.

func RunUser added in v0.1.6

func RunUser(ctx context.Context, dir string, args []string, limit int) (out string, code int, truncated bool, err error)

RunUser runs git args in dir as a person would and returns what it printed, stdout and stderr together, up to limit bytes (the rest is dropped and truncated set). A command that fails is not an error: its exit code says so. err is for a git that could not run at all, or ctx ending first.

func SetBranch added in v0.1.4

func SetBranch(ctx context.Context, root, branch, commit string) error

SetBranch points branch at commit, creating it if needed.

func Slug

func Slug(s string) string

Slug makes s safe for a directory or branch component: lowercase, with runs of other characters (including "/") collapsed to "-".

func StageChanges added in v0.1.9

func StageChanges(ctx context.Context, dir string, files []string, patch string) error

StageChanges is git add: the hunks in patch and every path in files put in the index, ready for a commit of what is staged. A patch that no longer applies stages nothing (ErrPatchStale), files included.

func TouchedFiles added in v0.1.9

func TouchedFiles(ctx context.Context, dir, base string) ([]string, error)

TouchedFiles lists what a checkout has changed since it left base: what it committed and what it has not, untracked files included — the files another branch's agent could collide with. Paths are relative to the checkout and sorted.

func UndoRebase added in v0.2.1

func UndoRebase(ctx context.Context, dir, branch, before, after string) error

UndoRebase puts branch back at before, in dir where it is checked out, if it is still at after and has nothing uncommitted: the rewrite stays in the reflog, so this too can be undone.

func Unmerged added in v0.1.1

func Unmerged(ctx context.Context, root, branch, base string) (int, error)

Unmerged counts the commits on branch that are in none of base, base's upstream and branch's upstream, i.e. what deleting the branch would lose. A branch whose changes base (or its upstream) already has, say because it was squash-merged, counts 0.

A count it could not make is an error, never 0: callers delete a branch that loses nothing, and a git that failed or a context that ran out says nothing about what would be lost. A branch that is not there is ErrNoBranch.

func Unreachable added in v0.1.1

func Unreachable(ctx context.Context, dir string) (int, error)

Unreachable counts the commits of a detached checkout at dir that no branch or remote-tracking branch has: what removing it would lose.

func UnstageChanges added in v0.1.9

func UnstageChanges(ctx context.Context, dir string, files []string, patch string) error

UnstageChanges takes paths, or the hunks in patch (as staged: a diff of the index against HEAD), back out of the index, leaving the files on disk as they are. In a repository with no commits yet there is no HEAD to go back to, so the paths are simply dropped from the index.

func UntrackedFiles

func UntrackedFiles(ctx context.Context, dir string, patterns []string, ignored bool) ([]string, error)

UntrackedFiles lists files in the checkout at dir that git does not track and that match any of patterns, git glob pathspecs relative to dir such as ".env" or "config/*.local.json". With ignored it lists the files git ignores, otherwise the untracked files it doesn't.

func ValidBranchName

func ValidBranchName(ctx context.Context, root, name string) error

ValidBranchName reports whether name is acceptable as a new branch name.

func WorkPatches added in v0.1.4

func WorkPatches(ctx context.Context, dir string) (staged, unstaged []byte, err error)

WorkPatches are the uncommitted changes in the checkout at dir as binary patches: what is staged, and what is changed on top of that.

func WorktreeDir

func WorktreeDir(root, branch string) string

WorktreeDir is where a worktree for branch lives: a sibling directory of the repository named <repo>.worktrees.

Types

type Branch

type Branch struct {
	Name       string
	Upstream   string // e.g. "origin/feat", "" if none
	Gone       bool   // upstream configured but deleted
	Ahead      int    // vs upstream
	Behind     int
	BaseAhead  int // commits on branch not in base
	BaseBehind int // commits on base not in branch
	Committed  time.Time
	Subject    string
}

Branch is a local branch with its tracking and base divergence.

func Branches

func Branches(ctx context.Context, root, base string) ([]Branch, error)

Branches lists local branches, most recently committed first, with divergence from base. An unresolvable base leaves the base counts at 0.

type Changes

type Changes struct {
	Base    string
	Files   []FileChange // sorted by path
	Commits []Commit     // newest first, capped at maxCommits
}

Changes is what a worktree or branch has changed relative to a base.

func BranchChanges

func BranchChanges(ctx context.Context, root, branch, base string) (Changes, error)

BranchChanges lists the files branch changed since it forked from base and the commits it has that base lacks. It works on branches that are not checked out anywhere.

func WorktreeChanges

func WorktreeChanges(ctx context.Context, path, base string) (Changes, error)

WorktreeChanges lists uncommitted changes (staged, unstaged and untracked) in the worktree at path, plus the commits HEAD has that base lacks.

type Commit

type Commit struct {
	Hash    string // full
	Subject string
	Author  string
	Time    time.Time
}

Commit is one commit in a log.

type CommitDetail added in v0.1.9

type CommitDetail struct {
	Hash    string
	Parents []string
	Author  string
	Email   string
	Time    time.Time
	Subject string
	Body    string
	// Files are what it changed against its first parent (the root commit:
	// against nothing).
	Files []FileStat
}

CommitDetail is a commit, its message whole, and the files it changed.

func ShowCommit added in v0.1.9

func ShowCommit(ctx context.Context, dir, rev string) (CommitDetail, error)

ShowCommit reads a commit and the files it changed.

type Compare added in v0.1.9

type Compare struct {
	Files   []FileStat
	Commits int
}

Compare is what changed from one commit to another, and how many commits that took.

func CompareCommits added in v0.1.9

func CompareCommits(ctx context.Context, dir, from, to string) (Compare, error)

CompareCommits is what changed between from and to, and the commits reachable from to but not from.

type ConflictError added in v0.1.1

type ConflictError struct {
	Branch, Into string
	Files        []string
}

ConflictError is a merge that stopped on conflicts and was undone.

func (*ConflictError) Error added in v0.1.1

func (e *ConflictError) Error() string

type FileChange

type FileChange struct {
	Path     string
	OrigPath string // for renames
	Code     string // one of "M","A","D","R","C","T","U" (conflict),"?" (untracked)
	Staged   bool
	Unstaged bool
	Added    int
	Deleted  int
	Binary   bool
}

FileChange is one changed file.

func StatusFiles added in v0.1.1

func StatusFiles(ctx context.Context, dir string) ([]FileChange, error)

StatusFiles lists the uncommitted changes in the checkout at dir, untracked files included.

type FileStat added in v0.1.9

type FileStat struct {
	Path     string
	OrigPath string // a rename's old name
	Code     string // A M D R C T
	Added    int
	Deleted  int
	Binary   bool
}

FileStat is one file a commit or a range changed.

type LogCommit added in v0.1.9

type LogCommit struct {
	Hash    string
	Parents []string
	Author  string
	Time    time.Time
	Subject string
	// Refs as git decorates them: "HEAD -> main", "origin/main",
	// "tag: v1.0".
	Refs []string
}

LogCommit is one commit of a repository's history, with what a graph needs to draw it: its parents, and the refs that point at it.

func Log added in v0.1.9

func Log(ctx context.Context, dir string, limit int) (commits []LogCommit, more bool, err error)

Log is the history reachable from every local branch and tag and from HEAD, newest first in topological order, so a commit always comes before its parents. It reads at most limit commits; more says there were others. A repository with no commits yet has no history, not an error.

type OntoConflictError added in v0.1.9

type OntoConflictError struct {
	Branch, Onto string
	Files        []string
}

OntoConflictError is a rebase onto the base that stopped on conflicts and was undone: the branch is as it was.

func (*OntoConflictError) Error added in v0.1.9

func (e *OntoConflictError) Error() string

type PushRejectedError added in v0.1.5

type PushRejectedError struct {
	Branch, Remote string
}

PushRejectedError is a push the remote refused because it holds commits the checkout does not have: somebody else pushed, or the same branch was pushed from another machine. The branch has to take them first.

func (*PushRejectedError) Error added in v0.1.5

func (e *PushRejectedError) Error() string

type Rebase added in v0.2.1

type Rebase struct {
	Branch        string
	Before, After string
	Onto          string
	At            time.Time
}

Rebase is a branch's newest rebase: its tip before and after, and the commit it was put on.

func LastRebase added in v0.2.1

func LastRebase(ctx context.Context, dir, branch string) (*Rebase, error)

LastRebase is branch's rebase when that is the newest thing done to it, or nil: a commit, reset or push since and it is no longer news.

type RebaseConflictError added in v0.1.5

type RebaseConflictError struct {
	Branch, Remote string
	Files          []string
}

RebaseConflictError is a rebase that stopped on conflicts and was undone: the branch is as it was and nothing was pushed.

func (*RebaseConflictError) Error added in v0.1.5

func (e *RebaseConflictError) Error() string

type Repo

type Repo struct {
	Root      string // main worktree top level (for a linked worktree dir, still the MAIN repo root)
	CommonDir string // absolute path of the shared .git dir
}

Repo identifies a repository by its main worktree.

func Discover

func Discover(ctx context.Context, dir string) (Repo, error)

Discover finds the repository containing dir.

type RepoFormat added in v0.2.1

type RepoFormat struct {
	Objects string
	Refs    string
}

RepoFormat is how a repository stores itself: its object hash (sha1, or sha256 as git 3 makes new repositories) and its refs backend (files, or reftable). Both are "" outside a repository.

func Format added in v0.2.1

func Format(ctx context.Context, dir string) RepoFormat

Format reads dir's repository format. A git older than 2.45 cannot say its refs backend, and cannot open a reftable repository either, so the refs of one it can read are files.

type Rewrite added in v0.2.1

type Rewrite struct {
	Old, New string
	Subject  string
	Change   string
}

Rewrite is one commit before and after the rebase, by short hash.

func Rewritten added in v0.2.1

func Rewritten(ctx context.Context, dir string, r *Rebase) ([]Rewrite, error)

Rewritten pairs the branch's commits before the rebase with those after, oldest first, saying of each whether its change is what it was. A commit whose conflict was resolved is the one that changed.

type Status

type Status struct {
	Staged, Unstaged, Untracked, Conflicts int // file counts
	Files                                  int // distinct changed files incl. untracked
	Added, Deleted                         int // lines vs HEAD (tracked files; binary files count 0)
}

Status summarises uncommitted changes in a worktree.

func WorktreeStatus

func WorktreeStatus(ctx context.Context, path string) (Status, error)

WorktreeStatus counts the uncommitted changes in the worktree at path.

func (Status) Clean

func (s Status) Clean() bool

Clean reports whether the worktree has no changes at all.

type Worktree

type Worktree struct {
	Path     string // absolute, symlinks resolved
	Branch   string // short name, "" when detached
	Head     string // commit hash
	Detached bool
	Main     bool // the main worktree (first entry)
	Locked   bool
	Prunable bool
}

Worktree is one entry of `git worktree list`.

func Worktrees

func Worktrees(ctx context.Context, root string) ([]Worktree, error)

Worktrees lists the worktrees of the repository at root, main first.

Jump to

Keyboard shortcuts

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