Documentation
¶
Overview ¶
Package worktrees discovers Git worktrees without mutating repositories.
Index ¶
- Variables
- func Contains(worktreePath, cwd string) bool
- type CreateResult
- type Manager
- func (m *Manager) ApplySessions(result *Result)
- func (m *Manager) Create(source, branch, baseRef string) (CreateResult, error)
- func (m *Manager) CreateWithReadyBinding(source, branch, baseRef string, bind func(CreateResult)) (CreateResult, error)
- func (m *Manager) Discover(cwd string) (Result, error)
- func (m *Manager) DiscoverAllManagedRepositories() Result
- func (m *Manager) ManagedBindingForPath(cwd string) (string, bool)
- func (m *Manager) ReadOnly() bool
- func (m *Manager) ReconcileAll() error
- func (m *Manager) Record(id string) (Record, bool)
- func (m *Manager) Records() []Record
- func (m *Manager) Remove(id string, liveSessionIDs func() []string) error
- func (m *Manager) Reserve(commonDir, repoRoot, branch, baseRef string) (Record, error)
- func (m *Manager) RollbackCreated(id string) error
- func (m *Manager) Transition(id string, expected, next State) error
- func (m *Manager) WithReadyBinding(id, cwd string, operation func(canonicalPath string) error) error
- func (m *Manager) WithRepository(commonDir string, operation func() error) error
- type Overview
- type Record
- type Result
- type Runner
- type State
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidRef = errors.New("worktrees: invalid ref") ErrBranchExists = errors.New("worktrees: branch exists") ErrBranchCheckedOut = errors.New("worktrees: branch checked out") ErrRecoveryRequired = errors.New("worktrees: recovery required") ErrNotFound = errors.New("worktrees: not found") ErrNotManaged = errors.New("worktrees: not managed") ErrMain = errors.New("worktrees: main worktree") ErrDirty = errors.New("worktrees: dirty") ErrInUse = errors.New("worktrees: in use") ErrLocked = errors.New("worktrees: locked") ErrStatusUnknown = errors.New("worktrees: status unknown") ErrIdentityChanged = errors.New("worktrees: identity changed") ErrRemoveFailed = errors.New("worktrees: remove failed") )
var ErrCorruptStore = errors.New("worktrees: corrupt metadata")
var ErrDurabilityUncertain = errors.New("worktrees: replacement visible but directory sync failed")
var ErrFutureVersion = errors.New("worktrees: metadata version is newer than daemon")
var ErrNotRepository = errors.New("worktrees: not a repository")
var ErrPartial = errors.New("worktrees: status incomplete")
var ErrTooMany = errors.New("worktrees: result limit exceeded")
Functions ¶
Types ¶
type CreateResult ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) ApplySessions ¶
func (*Manager) Create ¶
func (m *Manager) Create(source, branch, baseRef string) (CreateResult, error)
Create adds a daemon-owned worktree. All validation and mutation for one repository is serialized, while session creation remains outside this lock.
func (*Manager) CreateWithReadyBinding ¶
func (m *Manager) CreateWithReadyBinding(source, branch, baseRef string, bind func(CreateResult)) (CreateResult, error)
CreateWithReadyBinding keeps the repository transaction locked through the initial session attachment callback, so removal cannot observe a ready zero-session gap between worktree creation and binding.
func (*Manager) DiscoverAllManagedRepositories ¶
DiscoverAllManagedRepositories returns fresh observations for every repository still referenced by trusted ownership metadata. This keeps zero-session managed worktrees visible for explicit reopen/removal.
func (*Manager) ManagedBindingForPath ¶
ManagedBindingForPath returns the trusted managed record containing cwd, including transitional records so a legacy request cannot race removal by omitting worktree_id.
func (*Manager) ReconcileAll ¶
ReconcileAll checks each recorded repository once. It only updates provenance state; it never creates, removes, or force-cleans a worktree.
func (*Manager) Remove ¶
Remove deletes only the checkout of a currently clean, unused daemon-owned worktree. The branch and commits are deliberately left intact. Callers pass the live session IDs observed immediately before entry; all Git and path invariants are re-read after acquiring the repository lock.
func (*Manager) RollbackCreated ¶
RollbackCreated removes only a clean worktree produced by this manager.
func (*Manager) WithReadyBinding ¶
func (m *Manager) WithReadyBinding(id, cwd string, operation func(canonicalPath string) error) error
WithReadyBinding serializes session attachment with worktree removal. The callback runs only while id still names the trusted ready checkout at cwd. It must stay short and must not perform Git I/O.
type Overview ¶
type Overview struct {
ID string `json:"id"`
Managed bool `json:"managed"`
Path string `json:"path"`
RepoRoot string `json:"repo_root"`
Branch string `json:"branch,omitempty"`
Head string `json:"head,omitempty"`
Detached bool `json:"detached"`
Locked bool `json:"locked"`
Prunable bool `json:"prunable"`
IsMain bool `json:"is_main"`
Dirty bool `json:"dirty"`
StatusKnown bool `json:"status_known"`
StatusError string `json:"status_error,omitempty"`
ChangeCount int `json:"change_count"`
SessionIDs []string `json:"session_ids"`
CanRemove bool `json:"can_remove"`
RemoveBlocker string `json:"remove_blocker,omitempty"`
State string `json:"state,omitempty"`
BindingHealth string `json:"binding_health,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
LastActivity time.Time `json:"last_activity,omitempty"`
Stale bool `json:"stale"`
}
func ParsePorcelain ¶
type Record ¶
type Record struct {
ID string `json:"id"`
CommonDir string `json:"common_dir"`
RepoRoot string `json:"repo_root"`
Path string `json:"path"`
Branch string `json:"branch,omitempty"`
BaseRef string `json:"base_ref,omitempty"`
CreatedAt time.Time `json:"created_at"`
LastActivityAt time.Time `json:"last_activity_at,omitempty"`
LastDirtyTransitionAt time.Time `json:"last_dirty_transition_at,omitempty"`
State State `json:"state"`
}