cliworktree

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StatWorktreeSwitchPath = os.Stat
	AbsWorktreeSwitchPath  = filepath.Abs
	EvalWorktreeSwitchPath = filepath.EvalSymlinks
	GetwdWorktreeSwitch    = os.Getwd
	RelWorktreeSwitchPath  = filepath.Rel
)
View Source
var CanonicalWorktreeDialogRoot = CanonicalMarkerRoot

CanonicalWorktreeDialogRoot is the canonical worktree dialog root value.

View Source
var ErrUnmanagedWorktree = errors.New("worktree has no managed lifecycle binding")

ErrUnmanagedWorktree marks a worktree that has no valid lifecycle binding: its marker is unreadable or its instance is not active in storage. The caller removes the physical worktree directly and cleans storage rows by name, so HDD space is freed even when the storage layer has no entry.

View Source
var OpenRepositoryContextStoreFunc func(root string) (*storage.SQLite, error)

OpenRepositoryContextStoreFunc opens the repository-level context store for root. Wired by internal/cli's init (see cli.wireCliworktree) rather than imported directly: cli's own repository-store resolution (repositorySessionStorePath in chat_repository_binding.go) needs worktree helpers this package exports (WorktreeRoutePrincipal, ReadWorktreeMarker, CanonicalMarkerRoot), so cliworktree importing internal/cli here would close an import cycle (cli -> cliworktree -> cli). BLOCKER: this indirection is a stopgap, not a design decision - the task briefing for this slice assumed internal/composition already imported internal/cli (false, verified) and did not anticipate this specific cycle. Flagged for follow-up: a real fix likely needs repositorySessionStorePath's non-worktree config-resolution logic split out of chat_repository_binding.go so cliworktree can depend on it directly without pulling in the rest of that file's worktree-session-binding logic.

Functions

func AddWorktreeRecoveryRows

func AddWorktreeRecoveryRows(list []vcs.WorktreeInfo, infos []contextstate.WorktreeInstanceInfo) []vcs.WorktreeInfo

AddWorktreeRecoveryRows implements add worktree recovery rows.

func AdoptManagedWorktree

func AdoptManagedWorktree(root string, wt *vcs.WorktreeInfo) (contextstate.WorktreeInstance, error)

func BeginManagedWorktreeRemoval

func BeginManagedWorktreeRemoval(root string, wt *vcs.WorktreeInfo) (contextstate.WorktreeInstance, error)

func BeginManagedWorktreeRemovalForSession

func BeginManagedWorktreeRemovalForSession(sess *chat.Session, root string, wt *vcs.WorktreeInfo) (contextstate.WorktreeInstance, error)

func BeginManagedWorktreeRemovalForSessionExpected

func BeginManagedWorktreeRemovalForSessionExpected(sess *chat.Session, root string, wt *vcs.WorktreeInfo, expected contextstate.WorktreeInstance, requireExpected bool) (contextstate.WorktreeInstance, error)

BeginManagedWorktreeRemovalForSessionExpected is relocated from internal/legacytui/worktree_dialog.go: it is pure business logic with no TUI dependency, needed unqualified there and here.

func BeginManagedWorktreeRemovalInStore

func BeginManagedWorktreeRemovalInStore(store *storage.SQLite, root string, wt *vcs.WorktreeInfo) (contextstate.WorktreeInstance, error)

func BeginManagedWorktreeRemovalInStoreExpected

func BeginManagedWorktreeRemovalInStoreExpected(store *storage.SQLite, root string, wt *vcs.WorktreeInfo, expected contextstate.WorktreeInstance, requireExpected bool) (contextstate.WorktreeInstance, error)

BeginManagedWorktreeRemovalInStoreExpected implements begin managed worktree removal in store expected.

func CanonicalMarkerRoot

func CanonicalMarkerRoot(root string) (string, error)

func ClassifyMissingWorktreeMarker

func ClassifyMissingWorktreeMarker(store *storage.SQLite, principal contextstate.Principal, worktree, canonicalPath string) (contextstate.WorktreeInstanceInfo, bool, error)

ClassifyMissingWorktreeMarker implements classify missing worktree marker.

func CleanupStaleWorktreeRows

func CleanupStaleWorktreeRows(store *storage.SQLite, principal contextstate.Principal, name string) (bool, error)

CleanupStaleWorktreeRows fences and removes every storage row for one worktree name, tombstoning its sessions. It reports whether any row existed. Call it only when the physical worktree is gone: the name owns at most one non-deleted instance, so a same-name replacement is never touched.

func CreateManagedWorktree

func CreateManagedWorktree(root, name, baseRef, branchPrefix string) (*vcs.WorktreeInfo, error)

CreateManagedWorktree reserves lifecycle state before it creates Git state. A retry completes a retained creation with the same instance ID.

func CreateManagedWorktreeInStore

func CreateManagedWorktreeInStore(store *storage.SQLite, root, name, baseRef, branchPrefix string) (*vcs.WorktreeInfo, error)

func CreateManagedWorktreeInStoreLocked

func CreateManagedWorktreeInStoreLocked(store *storage.SQLite, root, name, baseRef, branchPrefix string, result *contextstate.WorktreeInstance, lease *os.File) (*vcs.WorktreeInfo, error)

CreateManagedWorktreeInStoreLocked implements create managed worktree in store locked.

func CreateManagedWorktreeInStoreWithInstance

func CreateManagedWorktreeInStoreWithInstance(store *storage.SQLite, root, name, baseRef, branchPrefix string, result *contextstate.WorktreeInstance) (*vcs.WorktreeInfo, error)

CreateManagedWorktreeInStoreWithInstance creates a managed worktree in store and records the resulting instance in result. Relocated from internal/legacytui/worktree_dialog_create.go: it is pure business logic with no TUI dependency, needed unqualified there and here.

func FinishManagedWorktreeRemoval

func FinishManagedWorktreeRemoval(root string, instance contextstate.WorktreeInstance) error

FinishManagedWorktreeRemoval implements finish managed worktree removal.

func FinishManagedWorktreeRemovalInStore

func FinishManagedWorktreeRemovalInStore(store *storage.SQLite, root string, instance contextstate.WorktreeInstance) error

FinishManagedWorktreeRemovalInStore implements finish managed worktree removal in store.

func LockWorktreeLifecycle

func LockWorktreeLifecycle(root, name string) (*worktreeLifecycleLock, error)

LockWorktreeLifecycle implements lock worktree lifecycle.

func LockWorktreeMarkerFile

func LockWorktreeMarkerFile(file *os.File) (func(), error)

func OpenMarkerExcludeLockFile

func OpenMarkerExcludeLockFile(root *os.Root, path string) (*os.File, error)

func ReactivateManagedWorktree

func ReactivateManagedWorktree(root string, instance contextstate.WorktreeInstance) error

ReactivateManagedWorktree implements reactivate managed worktree.

func ReactivateManagedWorktreeInStore

func ReactivateManagedWorktreeInStore(store *storage.SQLite, root string, instance contextstate.WorktreeInstance) error

ReactivateManagedWorktreeInStore implements reactivate managed worktree in store.

func ReadMarkerAtCanonicalRoot

func ReadMarkerAtCanonicalRoot(root string) (contextstate.WorktreeInstance, string, error)

func ReadWorktreeMarker

func ReadWorktreeMarker(root string) (contextstate.WorktreeInstance, error)

ReadWorktreeMarker implements read worktree marker.

func RecoverManagedWorktreeCreationInStore

func RecoverManagedWorktreeCreationInStore(store *storage.SQLite, root string, info contextstate.WorktreeInstanceInfo) (*vcs.WorktreeInfo, error)

RecoverManagedWorktreeCreationInStore implements recover managed worktree creation in store.

func RecoverManagedWorktreeRemoval

func RecoverManagedWorktreeRemoval(root, name, branchPrefix string) (bool, error)

func RecoverManagedWorktreeRemovalInfoInStoreLocked

func RecoverManagedWorktreeRemovalInfoInStoreLocked(store *storage.SQLite, root string, info contextstate.WorktreeInstanceInfo, branchPrefix string, lease *os.File) error

RecoverManagedWorktreeRemovalInfoInStoreLocked implements recover managed worktree removal info in store locked.

func RegisterManagedWorktreeInStore

func RegisterManagedWorktreeInStore(store *storage.SQLite, root string, wt *vcs.WorktreeInfo) (contextstate.WorktreeInstance, error)

func RegisterWorktreeRoute

func RegisterWorktreeRoute(root string, wt *vcs.WorktreeInfo) error

RegisterWorktreeRoute creates the route shown in /sessions for a worktree.

func RemoveUnmanagedWorktree

func RemoveUnmanagedWorktree(root string, wt *vcs.WorktreeInfo, branchPrefix string, lease *os.File) error

RemoveUnmanagedWorktree removes a worktree that has no valid lifecycle binding. It removes the physical worktree first so HDD space is always freed, then prunes stale Git metadata and cleans storage rows for the name.

func RemoveWorktreeLocked

func RemoveWorktreeLocked(root, name, branchPrefix string, lease *os.File) (bool, error)

RemoveWorktreeLocked removes one worktree by name under an acquired lifecycle lock. It runs deletion recovery, the managed removal, the unmanaged fallback for worktrees without a storage binding, and ghost cleanup for names whose Git worktree is gone. It reports whether the worktree or its storage rows were removed.

func RemoveWorktreeRoute

func RemoveWorktreeRoute(root, name string) error

RemoveWorktreeRoute removes the route after Git has removed its worktree.

func RemoveWorktreeRouteForSession

func RemoveWorktreeRouteForSession(sess *chat.Session, root, name string) error

func RunWorktree

func RunWorktree(args []string) error

RunWorktree handles worktree CLI commands.

func RunWorktreeWithIO

func RunWorktreeWithIO(args []string, stdout io.Writer) error

func SnapshotWorktreeDialogBindings

func SnapshotWorktreeDialogBindings(store *storage.SQLite, principal contextstate.Principal, worktrees []vcs.WorktreeInfo, recoveries []contextstate.WorktreeInstanceInfo) map[string]WorktreeDialogBinding

SnapshotWorktreeDialogBindings implements snapshot worktree dialog bindings.

func ValidateExpectedWorktreeInstanceInStore

func ValidateExpectedWorktreeInstanceInStore(store *storage.SQLite, root, dir string, expected contextstate.WorktreeInstance) error

ValidateExpectedWorktreeInstanceInStore implements validate expected worktree instance in store.

func WorktreeContainsCurrentDir

func WorktreeContainsCurrentDir(path string) bool

WorktreeContainsCurrentDir implements worktree contains current dir.

func WorktreeMarkerPath

func WorktreeMarkerPath(root string) string

func WorktreeRecoveryLabel

func WorktreeRecoveryLabel(state contextstate.WorktreeInstanceState) string

WorktreeRecoveryLabel implements worktree recovery label.

func WorktreeRoutePrincipal

func WorktreeRoutePrincipal(root string) (contextstate.Principal, error)

WorktreeRoutePrincipal implements worktree route principal.

func WriteWorktreeList

func WriteWorktreeList(stdout io.Writer, worktrees []vcs.WorktreeInfo, deleting []contextstate.WorktreeInstanceInfo)

func WriteWorktreeMarker

func WriteWorktreeMarker(root string, instance contextstate.WorktreeInstance) error

Types

type WorktreeDialogBinding

type WorktreeDialogBinding struct {
	Instance contextstate.WorktreeInstance
	Err      error
}

WorktreeDialogBinding holds worktree dialog binding state.

func SnapshotWorktreeDialogBinding

func SnapshotWorktreeDialogBinding(store *storage.SQLite, principal contextstate.Principal, worktree vcs.WorktreeInfo) WorktreeDialogBinding

type WorktreeRecoveryRow

type WorktreeRecoveryRow struct {
	Info contextstate.WorktreeInstanceInfo
}

WorktreeRecoveryRow holds worktree recovery row state.

Jump to

Keyboard shortcuts

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