worktrees

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 12 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 worktrees audits the git worktrees of one repository: which are clean, which carry work the integration branch does not, and which could be removed. See docs/runtime/worktrees-tool-design.md.

It runs git and nothing else. What only the room knows, whether atrium made a worktree and whether a card is still using it, comes in through Input.Judge, so the git half is tested against a real repository and the card half where the cards are.

Index

Constants

View Source
const (
	// CallBound is how long a whole audit may take, and CommandBound how long any one git command of it may.
	CallBound    = 60 * time.Second
	CommandBound = 20 * time.Second
	// MaxLines is how many worktrees an answer lists. The rest are counted in the trailer and not measured.
	MaxLines = 100
)
View Source
const (
	ReasonNotAtriums = "not atrium's"
	ReasonMain       = "main checkout"
	ReasonProtected  = "protected branch"
	ReasonDirty      = "dirty"
	ReasonUnlanded   = "unlanded"
	ReasonLocked     = "locked"
	ReasonNotListed  = "not a worktree"
	ReasonUnknown    = "unknown"
)

Reasons a worktree is kept, as they read on a line.

Variables

This section is empty.

Functions

func Format

func Format(res *Result) string

Format is the answer as text: a header, a line per worktree and at most one trailer.

func SamePath

func SamePath(a, b string) bool

SamePath is whether two paths are one, after Clean and slashes, and case where the filesystem folds it.

Types

type Input

type Input struct {
	// Repo is a directory inside any checkout or worktree of the repository.
	Repo string
	// Prefix and Paths narrow the answer. Both together are refused.
	Prefix string
	Paths  []string
	// Judge answers for the room. Nil reads as every worktree being atrium's, with nothing after.
	Judge func(path string) Judgment
	// Runner runs git. Nil takes a runner bounded at CommandBound.
	Runner *gitsync.Runner
}

Input is one audit.

type Judgment

type Judgment struct {
	// Atriums is whether atrium made the worktree, by the ledger rule.
	Atriums bool
	// Later are the reasons that come after the git ones: a card in use, and reclaimBlock's sentence.
	Later []string
}

Judgment is what the room says of a worktree path.

type Line

type Line struct {
	Path   string `json:"path"`
	Branch string `json:"branch"`
	// Missing is a directory git lists that is gone.
	Missing  bool `json:"missing,omitempty"`
	Main     bool `json:"main,omitempty"`
	Locked   bool `json:"locked,omitempty"`
	Detached bool `json:"detached,omitempty"`
	// Dirty is the count of status lines, less an untracked root BRIEF.md or REPORT.md, which are Flags.
	Dirty int      `json:"dirty"`
	Flags []string `json:"flags,omitempty"`
	// Landed is the weakest evidence, ancestry, patch or subject. Empty when Unlanded is not 0 or nothing was measured.
	Landed   string `json:"landed,omitempty"`
	Unlanded int    `json:"unlanded"`
	Newest   string `json:"newest,omitempty"`
	Subject  string `json:"subject,omitempty"`
	// Unknown is why git could not answer, and the line is never removable.
	Unknown   string   `json:"unknown,omitempty"`
	Removable bool     `json:"removable"`
	Prune     bool     `json:"prune,omitempty"`
	Keep      []string `json:"keep,omitempty"`
	// NotListed is a path that was asked for and git does not list.
	NotListed bool `json:"not_listed,omitempty"`
	// contains filtered or unexported fields
}

Line is one worktree, with the fields the line prints.

func (Line) Format

func (l Line) Format(width int) string

Format is one worktree's line, its path padded to width.

type Refusal

type Refusal struct{ Why string }

Refusal is an audit that was not run, and the sentence that says why.

func (*Refusal) Error

func (r *Refusal) Error() string

type Result

type Result struct {
	Ref    string `json:"ref"`
	RefSHA string `json:"ref_sha"`
	// From is `hub` or `local`.
	From  string `json:"from"`
	Total int    `json:"total"`
	Lines []Line `json:"lines"`
	// More is how many worktrees were left out past MaxLines.
	More         int    `json:"more,omitempty"`
	Unknown      int    `json:"unknown,omitempty"`
	FirstUnknown string `json:"first_unknown,omitempty"`
	Text         string `json:"text"`
}

Result is an audit. Text is the answer as the tool says it.

func Audit

func Audit(ctx context.Context, in Input) (*Result, error)

Audit measures the worktrees of the repository.

type Update

type Update struct {
	Path    string `json:"path"`
	Branch  string `json:"branch"`
	Done    string `json:"done,omitempty"`
	Skipped string `json:"skipped,omitempty"`
}

Update is one worktree's outcome. Skipped says why nothing was done.

func Updates

func Updates(ctx context.Context, repo string, run *gitsync.Runner) ([]Update, error)

Updates fast-forwards every clean worktree of the repository whose branch has a live upstream, after one fetch that prunes. It never touches a dirty worktree, and every skip is reported with its reason.

Jump to

Keyboard shortcuts

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