worktree

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package worktree provides worktree management operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles worktree CRUD operations.

func NewManager

func NewManager(repoRoot string) *Manager

NewManager creates a new worktree manager.

func (*Manager) Create

func (m *Manager) Create(name string, baseSnapshotID *model.SnapshotID) (*model.WorktreeConfig, error)

Create creates a new worktree with the given name.

func (*Manager) CreateFromSnapshot

func (m *Manager) CreateFromSnapshot(name string, snapshotID model.SnapshotID, cloneFunc func(src, dst string) error) (*model.WorktreeConfig, error)

CreateFromSnapshot creates a new worktree with content cloned from a snapshot. This is similar to Fork but uses "create" semantics (for the --from flag).

func (*Manager) CreateStartedFromSnapshot

func (m *Manager) CreateStartedFromSnapshot(name string, snapshotID model.SnapshotID, cloneFunc func(src, dst string) error) (*model.WorktreeConfig, error)

CreateStartedFromSnapshot creates a new workspace whose files come from a save point, without inheriting that save point as workspace history.

func (*Manager) CreateStartedFromSnapshotAt added in v0.4.7

func (m *Manager) CreateStartedFromSnapshotAt(req StartedFromSnapshotRequest, cloneFunc func(src, dst string) error) (*model.WorktreeConfig, error)

CreateStartedFromSnapshotAt creates a new workspace at an explicit folder. If req.Name is empty, the workspace name is derived from req.Folder's basename.

func (*Manager) Fork

func (m *Manager) Fork(snapshotID model.SnapshotID, name string, cloneFunc func(src, dst string) error) (*model.WorktreeConfig, error)

Fork creates a new worktree from a snapshot with content cloned. The new worktree will be at HEAD state (can create snapshots immediately).

func (*Manager) Get

func (m *Manager) Get(name string) (*model.WorktreeConfig, error)

Get returns the config for a specific worktree.

func (*Manager) LastTransferRecord added in v0.4.7

func (m *Manager) LastTransferRecord() (transfer.Record, bool)

LastTransferRecord returns the final primary transfer from the most recent successful filesystem-aware workspace materialization handled by this manager.

func (*Manager) List

func (m *Manager) List() ([]*model.WorktreeConfig, error)

List returns all worktrees.

func (*Manager) Move added in v0.4.7

func (m *Manager) Move(name, newFolder string) error

Move moves a workspace folder without changing the workspace name.

func (*Manager) MoveLocked added in v0.4.7

func (m *Manager) MoveLocked(name, newFolder string) error

MoveLocked performs Move while the caller already holds the repository mutation lock.

func (*Manager) Path

func (m *Manager) Path(name string) (string, error)

Path returns the validated payload path for a worktree.

func (*Manager) PlanMove added in v0.4.7

func (m *Manager) PlanMove(name, newFolder string) (string, string, error)

PlanMove validates a path-only workspace move and returns the current and target folders without mutating either metadata or files.

func (*Manager) PlannedStartedFromPath

func (m *Manager) PlannedStartedFromPath(name string) (string, error)

PlannedStartedFromPath returns the workspace folder that CreateStartedFromSnapshot would publish, without creating staging, payload, or metadata paths.

func (*Manager) PlannedStartedFromWorkspace added in v0.4.7

func (m *Manager) PlannedStartedFromWorkspace(req StartedFromSnapshotRequest) (string, error)

PlannedStartedFromWorkspace returns the explicit workspace folder after validating the requested name, target, and current workspace registry.

func (*Manager) RebindRealPath

func (m *Manager) RebindRealPath(name, realPath string) error

RebindRealPath updates the workspace's destination-local real path after the caller has determined that the new binding is safe.

func (*Manager) Remove

func (m *Manager) Remove(name string) error

Remove deletes a workspace. Fails if the workspace is main.

func (*Manager) RemoveLocked added in v0.4.7

func (m *Manager) RemoveLocked(name string) error

RemoveLocked performs Remove while the caller already holds the repository mutation lock.

func (*Manager) Rename

func (m *Manager) Rename(oldName, newName string) error

Rename renames a worktree.

func (*Manager) RenameLocked added in v0.4.7

func (m *Manager) RenameLocked(oldName, newName string) error

RenameLocked performs Rename while the caller already holds the repository mutation lock.

func (*Manager) SetLatest

func (m *Manager) SetLatest(name string, snapshotID model.SnapshotID) error

SetLatest updates both head and latest snapshot IDs for a worktree. This is used by snapshot creation to mark a new latest state.

func (*Manager) UpdateHead

func (m *Manager) UpdateHead(name string, snapshotID model.SnapshotID) error

UpdateHead atomically updates the head snapshot ID for a worktree. This is used by restore to move to a different point in history.

type StartedFromSnapshotRequest added in v0.4.7

type StartedFromSnapshotRequest struct {
	Name            string
	Folder          string
	SnapshotID      model.SnapshotID
	RequestedEngine model.EngineType
	TransferPlanner transfer.EnginePlanner
}

StartedFromSnapshotRequest describes a new workspace folder whose initial files come from a save point.

Jump to

Keyboard shortcuts

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