worktree

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 17 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 worktree is the host's inventory (目録) of worktrees: every repository stagent can find, each with every linked worktree git knows (who ever made it), and the other folders left in the worktree folder (置き場のほかのフォルダ). The bridge's worktree.* methods list, measure and remove them (ADR 0016).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inside

func Inside(s wire.Session, dir string) bool

Inside reports whether session s works inside dir (its cwd).

func List

func List(ctx context.Context, env []string, inv *Inventory, tasks []wire.Task, live []wire.Session) []wire.WorktreeRepo

List describes inv's repositories for worktree.list: each worktree with its task, live sessions (live: cwd inside it, or its task's), changes (task.Changes, the shared directories' links not counted), unpushed commits, whether git sees its head merged into its task's base or the default branch (task.Merged: squash and rebase merges too) and its refusal reasons (task.Refusals, as the removal's dry run tells them). A task's worktree a killed `git worktree add` left half made is shown unlocked and without changes: removing it is the task's 片付け, which takes it despite the add's lock, and nothing in it is the user's. Nothing takes git's optional locks.

func Measure

func Measure(ctx context.Context, dir string, exclude map[string]bool) (int64, time.Time)

Measure is the disk usage of dir (diskUsage: a file linked twice once) and the newest modification time in it, UTC to the second (zero when nothing could be read). Links (symbolic links, junctions) are counted as themselves, never followed; directories below dir in exclude (see Inventory.Exclude) are not counted; what cannot be read is skipped. The walk stops when ctx ends.

func PRs

func PRs(ctx context.Context, env []string, inv *Inventory, tasks []wire.Task) []wire.WorktreePR

PRs asks gh, in the source checkout, for the pull request of each worktree's branch of the repositories with a GitHub remote (`gh pr view <branch> --json number,state,url,headRefOid`; a PR task's worktree by the task's number, as task.remove asks: gh finds a fork's pull request by number only), at most parallel at once. A branch gh has nothing for (or gh missing, or failing) is left out. Merged: MERGED with the pull request's head the worktree's commit, as task.remove deletes a squash-merged branch.

func RemoveFolder

func RemoveFolder(dir string) error

RemoveFolder removes dir and everything in it. When that fails it makes what is read-only in it writable (Windows refuses to delete a read-only file; Unix, the entries of a directory without write permission), following no link, and tries again.

func Sizes

Sizes measures inv's listed source checkouts, worktrees whose directory is there and folders (Measure, each of them excluded from the others), at most parallel at once, until ctx ends. Total adds the worktrees and folders.

func TaskOf

func TaskOf(tasks []wire.Task, path string) *wire.Task

TaskOf is the task (not in_place) whose worktree is path, or nil.

func Top

func Top(ctx context.Context, dir string, n int, exclude map[string]bool) []wire.WorktreeFolderTop

Top lists the entries directly in dir by disk usage (Measure), largest first (then by name), at most n.

Types

type Hit

type Hit struct {
	Repo *Repo
	// Worktree is nil for the source checkout itself and for a folder.
	Worktree *task.Worktree
	Folder   *wire.WorktreeFolder
}

Hit is what Find found at a path.

type Inventory

type Inventory struct {
	// Folder is the worktree folder, canonical; "": none.
	Folder string
	// Repos are in the order of their path.
	Repos []Repo
	// Folders are in path order.
	Folders []wire.WorktreeFolder
}

Inventory is what Discover found.

func Discover

func Discover(ctx context.Context, src Sources) (*Inventory, error)

Discover finds the repositories of src and their worktrees, without changing anything. Each candidate directory — worktree_repos, the tasks' source checkouts and worktrees, the worktree folder's <x> and <x>/<y> and the watch folders' <x> that have a .git, the sessions' existing cwds — is taken to the nearest directory with a .git at or above it; unless that is a source checkout or worktree found already, `git worktree list` runs there and its first entry is the source checkout. A repository around another (dotfiles at ~) so hides none inside it. A candidate git fails for is skipped silently; git not found at all is the error.

func (*Inventory) Exclude

func (inv *Inventory) Exclude() map[string]bool

Exclude is what Measure and Top skip below the directory they measure: the source checkouts, worktrees and folders of inv.

func (*Inventory) Find

func (inv *Inventory) Find(path string) (Hit, bool)

Find looks path (canonical) up: a source checkout, a worktree or a folder; false when it is none.

func (*Inventory) Holds

func (inv *Inventory) Holds(dir string) bool

Holds reports whether a source checkout or worktree found lies in dir.

func (*Inventory) RepoPaths

func (inv *Inventory) RepoPaths() []string

RepoPaths are the source checkouts found (worktree_repos), sorted.

type Repo

type Repo struct {
	// Path is its source checkout (main worktree), canonical.
	Path string
	// DefaultBranch is "" when it cannot be told.
	DefaultBranch string
	// GitHub: a remote's URL is on github.com.
	GitHub bool
	// Worktrees are its linked worktrees in git's order.
	Worktrees []task.Worktree
}

Repo is a repository. Only one with linked worktrees is listed (List, Sizes): the source checkout alone has nothing to remove, and one around everything (dotfiles kept in git at ~) is not measured. All are remembered: a repository's name still makes <repo name> of the worktree folder after its last worktree went.

type Sources

type Sources struct {
	// Env is git's environment (nil: this process's).
	Env []string
	// Folder is the worktree folder (worktree の置き場); "": none.
	Folder string
	// Watch are the watch folders (見るフォルダ).
	Watch []string
	// Repos are the source checkouts found before (worktree_repos).
	Repos []string
	// Tasks are the task records: their source checkouts and worktrees.
	Tasks []wire.Task
	// Sessions are sessions, ended ones too: their cwds.
	Sessions []wire.Session
}

Sources are where Discover looks for repositories.

Jump to

Keyboard shortcuts

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