Documentation
¶
Overview ¶
Package worktrees is the git worktrees sessions work in apart from the user's checkout: made under .worktrees of a repository on a branch of their own, locked for the process or the session using them, archived to a ref before an idle one holding work is removed, restored from that ref, and reclaimed along with the branches merged upstream. Features that work in trees add to their upkeep through hooks: why they still need a tree, what they let go of before one is removed, the repositories they keep and what they reclaim after
Index ¶
- Constants
- func Claimed(branch string) bool
- func Dirty(tree, repo string, timeout time.Duration) bool
- func Expire(repo string, retentionDays float64, dryRun bool) ([]string, error)
- func Live(paths []string, exclude ...int) map[string][]int
- func PruneMissing(repo string, dryRun bool) ([]string, error)
- func ReclaimBranches(repo string, dryRun bool, records []BranchRecord) ([]string, error)
- func RefSafe(name string) string
- func Shallow(ctx context.Context, repo string, timeout time.Duration) bool
- func SizeMB(ctx context.Context, path string, timeout time.Duration) *int
- func StagedState(tree string) (string, error)
- func State(tree Tree) string
- func StillInUse(tree string, grace time.Duration, exclude ...int) bool
- func SubmoduleWork(ctx context.Context, tree string, gitlinks bool) (string, error)
- func Summary(repo string, sizeBelow int) (int, *int)
- func Tier(name string, hours float64) float64
- func Unpushed(tree string, timeout time.Duration) bool
- type Archive
- type ArchiveError
- type ArchiveMeta
- type ArchiveRemoval
- type ArchivedTree
- type BranchRecord
- type Decision
- type ExternalTree
- type Hooks
- type Leftover
- type Profiles
- type Registrant
- type Registry
- type RemovalBlock
- type Request
- type Restored
- type Settings
- type Skipped
- type Tree
- type TreeRecord
- type Worktrees
- func (w *Worktrees) ArchiveThenRemove(cfg *config.Config, repo, tree, reason string, maxMB float64, unlock bool, ...) (*ArchiveRemoval, error)
- func (w *Worktrees) Audit(ctx context.Context, cfg *config.Config, repo string, sizes bool, ...) ([]TreeRecord, error)
- func (w *Worktrees) Branches(ctx context.Context, cfg *config.Config, repo string, acting bool) ([]BranchRecord, error)
- func (w *Worktrees) Create(ctx context.Context, cfg *config.Config, repo string, request Request, ...) *Tree
- func (w *Worktrees) Execute(cfg *config.Config, repo string, plan []*Decision) ([]string, map[string]bool, []ArchivedTree)
- func (w *Worktrees) FinishSubagent(cfg *config.Config, tree Tree) Leftover
- func (w *Worktrees) Leave(cfg *config.Config, tree Tree, choice string, say func(string), exclude ...int) bool
- func (w *Worktrees) Plan(cfg *config.Config, repo string, hours float64, olderThanDays *float64) []*Decision
- func (w *Worktrees) PruneStale(ctx context.Context, cfg *config.Config, repo string, hours float64) error
- func (w *Worktrees) Reclaim(cfg *config.Config, repo string, dryRun bool, records []TreeRecord) []string
- func (w *Worktrees) Record(cfg *config.Config, tree Tree)
- func (w *Worktrees) Recreate(cfg *config.Config, cwd, session string) string
- func (w *Worktrees) Register(registrant Registrant)
- func (w *Worktrees) Restore(ctx context.Context, repo, name, target string) (*Restored, error)
- func (w *Worktrees) Retain(repo, tree, session string) bool
- func (w *Worktrees) Settings(cfg *config.Config) Settings
- func (w *Worktrees) Settle(cfg *config.Config, tree Tree, choice string, say func(string), exclude ...int)
- func (w *Worktrees) Subagent(ctx context.Context, cwd, id string) *Tree
- func (w *Worktrees) Sweep(cfg *config.Config, repo string, hours float64) error
Constants ¶
const ( KeepUnarchivable = "keep-unarchivable" KeepWorktreeRefs = "keep-worktree-refs" KeepLargeUntracked = "keep-large-untracked" KeepSubmoduleWork = "keep-submodule-work" )
How a removal blocker keeps a tree
const ( ExitKeep = "keep" ExitArchive = "archive" ExitDiscard = "discard" )
What the user may do with a tree holding work as they are done with it
const ArchivePrefix = "refs/icebath/archive/"
Ref namespace holding the archives of removed trees
const FilterDiscoveryFailed = "The git filters of the repository could not be found for certain."
Errors of a git run refused because the repository's filter drivers could not be found with certainty
const SubmoduleReason = "the submodule "
Start of every reason a submodule keeps a tree
Variables ¶
This section is empty.
Functions ¶
func Claimed ¶
Whether the branch lies where the trees icebath makes for sessions have theirs, those of subagents among them, or is one the sweep deletes once no tree has it checked out, such as one of a pull request: a name another feature must not give a branch of its own
func Dirty ¶
Whether the tree holds staged, unstaged or untracked changes, or edits git was told to overlook; true when git can't tell. Links back to the main checkout that .worktreeinclude made are no change
func Expire ¶
Deletes the archives older than the retention, none for zero, or only names them for a dry run: their refs
func Live ¶
Processes working in each of the paths, by the path as given: their folder, or on Linux a file they hold open, lies in it. The excluded processes are left out
func PruneMissing ¶
Drops the registrations of worktrees whose folder is gone, metadata only, or names them for a dry run
func ReclaimBranches ¶
func ReclaimBranches(repo string, dryRun bool, records []BranchRecord) ([]string, error)
Deletes every branch of an audit whose verdict deletes it, or names them for a dry run
func Shallow ¶
Whether the repository is a shallow clone, whose push state can't be told; false when git can't tell
func SizeMB ¶
Megabytes a folder takes, through du where there is one, else by walking it; nil when it could not be measured in time or before the context ended
func StagedState ¶
Digest of what the tree has staged, unchanged by a refresh of file times and moved by any add or remove
func State ¶
How a tree stands as its session ends: dirty, unpushed, or empty for one clean and pushed, or gone
func StillInUse ¶
Whether a process other than this one still works in the tree once the grace passed
func SubmoduleWork ¶
Why a submodule keeps the tree: a repository of submodules that removing the tree deletes, or a submodule whose work only its commit reference holds, any gitlink at all when gitlinks is set; empty when none does. Its runs only read, and stop once the context ends
func Summary ¶
How many trees .worktrees holds and the megabytes they take, not measured once they are at least sizeBelow
Types ¶
type Archive ¶
type Archive struct {
Ref string
Name string
Sha string
Created time.Time
Meta ArchiveMeta
// Digest of the staged entries of the index it captured, set as it is made
Staged string
}
One archive of a removed tree
func Archives ¶
Every archive of the repository, newest first; none when git can't list them or the context ended first
func Find ¶
Archive of the name or ref, else the newest archive of a tree of that name; nil when there is none
type ArchiveError ¶
type ArchiveError struct{ Message string }
Failure to snapshot or restore a tree, after which it must be kept
func (*ArchiveError) Error ¶
func (e *ArchiveError) Error() string
type ArchiveMeta ¶
type ArchiveMeta struct {
Version int `json:"version"`
Name string `json:"name"`
Path string `json:"path"`
RepoRoot string `json:"repo_root"`
// Branch it had checked out, empty when detached
Branch string `json:"branch"`
Head string `json:"head"`
IndexCommit string `json:"index_commit"`
Created int64 `json:"created"`
Reason string `json:"reason"`
Skipped []Skipped `json:"skipped_untracked"`
}
What an archive's commit message keeps of the tree
type ArchiveRemoval ¶
type ArchiveRemoval struct {
Ref string
// Branch kept with the tree gone, empty for none
KeptBranch string
Removed bool
// Why the tree was kept after its archive
WhyKept string
}
What archiving then removing one tree came to
type ArchivedTree ¶
type ArchivedTree struct {
Ref string `json:"ref"`
Removed bool `json:"removed"`
WhyKept string `json:"why_kept,omitempty"`
}
What the sweep did with one tree it archived
type BranchRecord ¶
type BranchRecord struct {
Name string `json:"name"`
Verdict string `json:"verdict"`
Reason string `json:"reason"`
}
One local branch with its verdict, delete or keep
type Decision ¶
type Decision struct {
Name string `json:"name"`
Path string `json:"path"`
Action string `json:"action"`
Reason string `json:"reason"`
AgeHours float64 `json:"age_hours"`
Mtime float64 `json:"mtime"`
Force bool `json:"force"`
Verdict string `json:"verdict"`
Lock string `json:"lock_state,omitempty"`
SizeMB *int `json:"size_mb"`
Tier float64 `json:"tier_hours"`
Planned float64 `json:"planned_at"`
// contains filtered or unexported fields
}
One planned action of the sweep for a tree, with what it was decided on
type ExternalTree ¶
type ExternalTree struct {
Path string `json:"path"`
Branch string `json:"branch"`
Locked bool `json:"locked"`
Missing bool `json:"missing"`
}
A worktree registered outside .worktrees, shown and never touched
type Hooks ¶
type Hooks struct {
// Why the feature still needs the tree, such as a scheduled job that runs in it; empty when it doesn't
Holds func(ctx context.Context, tree string) string
// Lets go of what the feature keeps rooted in the tree, such as language servers, before the tree is removed
Release func(tree string)
// Hears of a repository a tree was made or restored in, such as to keep its trees pruned on a schedule
Recorded func(ctx context.Context, repo string)
// Reclaims what the feature keeps for checkouts that are gone, once trees were pruned
Reclaim func(ctx context.Context)
}
What a feature that works in trees adds to their upkeep, each part left nil when it has none
type Leftover ¶
type Leftover struct {
Path string `json:"path"`
Branch string `json:"branch"`
Commits int `json:"commits"`
Dirty bool `json:"dirty"`
Pruned bool `json:"pruned"`
Archive string `json:"archive,omitempty"`
// What git could not tell, so the zero counts are no proof the subagent did nothing
Failed bool `json:"inspection_failed,omitempty"`
Note string `json:"note,omitempty"`
}
What a subagent left in its tree once it finished: the commits it made, whether the tree holds uncommitted work, and whether the tree was removed, archived first when it held work
type Profiles ¶
type Profiles struct {
Worktrees *Worktrees
}
Trees as profiles are renamed: the record a profile keeps of its trees moves with its folder, so the trees of repositories inside the folder are recorded, and linked by git, at where they lie now
type Registrant ¶
type Registrant interface {
Hooks() Hooks
}
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) Host ¶
Host the registry is nested in, through which plugins make, archive and reclaim trees
func (*Registry) Register ¶
func (r *Registry) Register(registrant Registrant)
type RemovalBlock ¶
Why a tree may not be removed and how it is kept
func Blocked ¶
func Blocked(tree string) *RemovalBlock
Why removing a clean tree would lose something no branch holds, nil when it is safe
func Blocker ¶
Why removing the tree would lose something no branch or archive holds: a submodule's work, a nested repository, a ref of its own, or untracked files too large for its archive; nil when it is safe. Anything that can't be checked keeps the tree, its checks stopped once the context ends among them
func Preflight ¶
func Preflight(tree string, maxMB float64) *RemovalBlock
Why archiving and removing the tree would lose something, nil when it is safe
type Request ¶
Asks for a tree: its name, none for a generated one, the process it is locked for, and whether it is a launch's own tree, kept for the session working in it once the launch ends and recorded so a resume makes it again
type Restored ¶
type Restored struct {
Path string
// Branch it is on, or that moved on or is checked out elsewhere when it is detached
Branch string
Detached bool
Head string
Ref string
Skipped []Skipped
}
What a restore made
type Settings ¶
type Settings struct {
// Idle trees holding work are archived and removed
ArchiveDirty bool
// Largest untracked file in MB an archive takes, any for zero
ArchiveMaxFileMB float64
// Days an archive is kept, for good for zero, and that length in words as a person is told it: as the settings write it when they name
// a variable, so no log shows the variable's value
ArchiveRetentionDays float64
ArchiveRetention string
// GB every tree together may take, any for zero
MaxTotalGB float64
}
Settings of the profile the archive and the sweep follow
type Tree ¶
type Tree struct {
Path string `json:"path"`
Branch string `json:"branch"`
Repo string `json:"repo_root"`
// What it was branched from
Base string `json:"-"`
}
A tree made for a session to work in
func (Tree) SubagentNote ¶
What the subagent is told of the tree it works in
type TreeRecord ¶
type TreeRecord struct {
Name string `json:"name"`
Path string `json:"path"`
Branch string `json:"branch"`
AgeDays float64 `json:"age_days"`
SizeMB *int `json:"size_mb"`
Verdict string `json:"verdict"`
Reason string `json:"reason"`
// Untracked files archived before the tree goes
Untracked []string `json:"untracked"`
}
One tree under .worktrees with its reclaim verdict
type Worktrees ¶
type Worktrees struct {
Registry
// contains filtered or unexported fields
}
func (*Worktrees) ArchiveThenRemove ¶
func (w *Worktrees) ArchiveThenRemove(cfg *config.Config, repo, tree, reason string, maxMB float64, unlock bool, heads func() (map[string]string, bool), keepBranch bool, exclude ...int) (*ArchiveRemoval, error)
Archives the tree, then removes it unless it changed meanwhile, is in use, or holds what the archive lacks; its branch goes too unless it is kept, protected or published. heads gives origin's branches, read in the profile's environment when nil
func (*Worktrees) Audit ¶
func (w *Worktrees) Audit(ctx context.Context, cfg *config.Config, repo string, sizes bool, olderThanDays *float64, acting bool) ([]TreeRecord, error)
Classifies every tree under .worktrees without changing anything, several trees side by side; olderThanDays, when given, only keeps reapable trees younger than it. Acting for a prune, a shallow clone is deepened first and origin asked for its branches anew; a read leaves the clone as it is, a shallow one noted on the verdicts that keep work not found upstream, and takes origin's branches as a read begun within headsFresh found them. Verdicts reached on a shallow clone's history are not kept. Its runs of git stop once the context ends, which it then answers
func (*Worktrees) Branches ¶
func (w *Worktrees) Branches(ctx context.Context, cfg *config.Config, repo string, acting bool) ([]BranchRecord, error)
Classifies every local branch by what of it upstream holds: deleted when merged or every commit is the same change as one upstream, and not checked out anywhere; kept when git can't tell. Acting for a prune, a shallow clone is deepened first in the profile's environment; a read leaves the clone as it is, a shallow one noted on the verdicts that keep commits not found upstream. Its runs of git stop once the context ends
func (*Worktrees) Create ¶
func (w *Worktrees) Create(ctx context.Context, cfg *config.Config, repo string, request Request, sync bool, say func(string)) *Tree
Makes an isolated tree of the repository under .worktrees on a branch icebath/<name> of its own, off the freshest base when the settings fetch first, its .worktreeinclude entries copied in and locked for the owner: the tree, nil when it could not be made, and what happened saying line by line
func (*Worktrees) Execute ¶
func (w *Worktrees) Execute(cfg *config.Config, repo string, plan []*Decision) ([]string, map[string]bool, []ArchivedTree)
Carries out a plan, checking each tree again right before it is archived or removed: the trees kept for their work, the branches kept, and what was archived
func (*Worktrees) FinishSubagent ¶
Inspects a finished subagent's tree: an empty clean one is removed with its branch, one holding work archived and removed with its branch kept, as the profile's settings allow
func (*Worktrees) Leave ¶
func (w *Worktrees) Leave(cfg *config.Config, tree Tree, choice string, say func(string), exclude ...int) bool
What becomes of a launch's own tree as the launch ends, after what the user chose: settled when no session waits to work in it, no other process works in it and nothing else serves it, else kept for the session that worked in it last, saying so. Whether it is gone
func (*Worktrees) Plan ¶
func (w *Worktrees) Plan(cfg *config.Config, repo string, hours float64, olderThanDays *float64) []*Decision
What the sweep would do with every tree under .worktrees, changing nothing: olderThanDays, when given, only holds back removals
func (*Worktrees) PruneStale ¶
func (w *Worktrees) PruneStale(ctx context.Context, cfg *config.Config, repo string, hours float64) error
Removes the trees of the repository idle past their tier and the branches no tree has, archiving the ones holding work first unless the settings act as the pruner before archives; then reclaims what features keep for checkouts that are gone
func (*Worktrees) Reclaim ¶
func (w *Worktrees) Reclaim(cfg *config.Config, repo string, dryRun bool, records []TreeRecord) []string
Removes every tree of an audit whose verdict reaps it, its untracked scratch archived first, or names them for a dry run
func (*Worktrees) Record ¶
Remembers a tree a launch made or a session moved into, never failing: the trees of repositories gone are dropped
func (*Worktrees) Recreate ¶
Makes again the recorded tree a resumed session's missing folder names, on its branch when that is still there, and keeps it for the session, the newest session working in it when none is named: the tree, empty when it can't
func (*Worktrees) Register ¶
func (w *Worktrees) Register(registrant Registrant)
Adds a registrant; a registry nested in the host reaches it through Host
func (*Worktrees) Restore ¶
Makes the archived tree again at its first path or the target, with its exact files and index
func (*Worktrees) Retain ¶
Locks the tree again for the session working in it, once the process that made it ends
func (*Worktrees) Settle ¶
func (w *Worktrees) Settle(cfg *config.Config, tree Tree, choice string, say func(string), exclude ...int)
Carries out what the user chose for a tree they are done with, else removes it with its branch when it is clean and pushed and nothing of it would be lost, saying why one is kept. The excluded processes don't count as working in it