worktree

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package worktree wraps the git CLI to manage linked worktrees. Git is the source of truth: nothing is persisted here — every operation reads or mutates what `git worktree` already knows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRoot

func DefaultRoot() string

DefaultRoot is where worktrees live unless configured otherwise.

Types

type Branch

type Branch struct {
	Name     string `json:"name"`
	IsLocal  bool   `json:"is_local"`
	IsRemote bool   `json:"is_remote"`
}

Branch is a branch name and where it is known from.

type Info

type Info struct {
	Path     string `json:"path"`
	Branch   string `json:"branch,omitempty"`
	Head     string `json:"head,omitempty"`
	IsMain   bool   `json:"is_main"`
	Detached bool   `json:"detached"`
}

Info describes one worktree of a repository.

type Manager

type Manager struct {
	// Root is the directory where new worktrees are created,
	// e.g. ~/.agent_composer/worktrees.
	Root string
}

Manager creates and inspects worktrees under a global root directory.

func (*Manager) Branches

func (m *Manager) Branches(ctx context.Context, repo string) ([]Branch, error)

Branches lists local and origin branches (as of the last fetch).

func (*Manager) Fetch

func (m *Manager) Fetch(ctx context.Context, repo string) error

Fetch updates origin refs so remote branches are current.

func (*Manager) List

func (m *Manager) List(ctx context.Context, repo string) ([]Info, error)

List returns every worktree of the repository, main checkout first.

func (*Manager) Prune

func (m *Manager) Prune(ctx context.Context, repo string) error

Prune drops stale administrative entries for manually deleted dirs.

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, repo, path string, force bool) error

Remove deletes a worktree (never its branch). Git refuses dirty worktrees unless force is set — that refusal is surfaced verbatim.

func (*Manager) RepoRoot

func (m *Manager) RepoRoot(ctx context.Context, path string) (string, bool, error)

RepoRoot resolves the enclosing git repository of path. ok is false when path is not inside a git repository (not an error — callers use it to decide whether to offer worktrees at all).

func (*Manager) Resolve

func (m *Manager) Resolve(ctx context.Context, repo, branch, base string) (string, bool, error)

Resolve returns the worktree directory for (repo, branch):

  1. the branch already has a worktree → reuse its path
  2. the branch exists without a worktree → check it out
  3. the branch does not exist → create it from base (default HEAD)

Jump to

Keyboard shortcuts

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