worktree

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AheadBehind

func AheadBehind(
	ctx context.Context, runner CommandRunner, path string,
) (ahead, behind int, hasUpstream bool, err error)

AheadBehind returns the number of commits the branch at path is ahead of and behind its upstream. hasUpstream is false when no upstream is configured; this is not an error.

func Dirty

func Dirty(ctx context.Context, runner CommandRunner, path string) (bool, error)

func MergedBranches

func MergedBranches(ctx context.Context, runner CommandRunner, base string) ([]string, error)

MergedBranches returns local branches already merged into base. It excludes base itself and any branch whose tip points at exactly the same commit as base — such branches have no unique history yet (freshly created, or fast- forwarded with no subsequent activity) and are not safe to auto-prune, since a fresh worktree's work-in-progress has no commits to mark it distinct.

func RemoteBranchExists

func RemoteBranchExists(
	ctx context.Context, runner CommandRunner,
	path, branch string,
) (exists, hasUpstream bool, err error)

RemoteBranchExists reports whether the branch at path has a configured upstream tracking ref and whether that remote still has the branch.

Returns (false, false, nil) when no upstream is configured — a local branch that was never pushed is not a "remote-gone" finding. Returns (false, true, nil) when an upstream is configured but the remote no longer has the branch.

Types

type CommandRunner

type CommandRunner interface {
	Run(ctx context.Context, name string, args ...string) ([]byte, error)
}

type CommitInfo

type CommitInfo struct {
	ShortSHA  string    `json:"sha"`
	Subject   string    `json:"subject"`
	Committed time.Time `json:"committed"`
}

func LastCommit

func LastCommit(ctx context.Context, runner CommandRunner, path string) (CommitInfo, error)

type ErrNotFound

type ErrNotFound struct {
	Branch string
}

ErrNotFound is returned when no worktree matches the requested branch.

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

type ExecRunner

type ExecRunner struct{ Dir string }

ExecRunner runs commands with os/exec. An empty Dir inherits the process working directory, so a caller that stands in the repo needs no Dir at all.

func (ExecRunner) Run

func (r ExecRunner) Run(ctx context.Context, name string, args ...string) ([]byte, error)

type Worktree

type Worktree struct {
	Path           string
	Branch         string // stripped of refs/heads/ prefix; "(detached)" when detached
	IsMain         bool   // true when .git entry is a directory, not a file
	Prunable       bool   // true when git considers the worktree stale (directory deleted)
	PrunableReason string // git's human-readable reason, e.g. "gitdir file points to non-existent location"
}

func FindByBranch

func FindByBranch(wts []Worktree, branch string) (Worktree, bool)

func FindOrErr

func FindOrErr(wts []Worktree, branch string) (Worktree, error)

FindOrErr wraps FindByBranch, returning ErrNotFound when no match exists.

func List

func List(ctx context.Context, runner CommandRunner) ([]Worktree, error)

func MainWorktree

func MainWorktree(wts []Worktree) (Worktree, error)

MainWorktree returns the worktree whose .git entry is a directory (the main repo).

Directories

Path Synopsis
Package worktreetest provides shared test helpers for packages that depend on worktree.CommandRunner.
Package worktreetest provides shared test helpers for packages that depend on worktree.CommandRunner.

Jump to

Keyboard shortcuts

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