worktree

package
v0.11.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0, MIT Imports: 15 Imported by: 0

Documentation

Overview

Package worktree manages isolated task checkouts without discarding user work.

Package worktree wraps `git worktree` for safe programmatic use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(repoDir, path, branch string) error

Add creates a new worktree at `path` checked out to `branch`. If the branch doesn't exist, git creates it from HEAD.

func Lock

func Lock(repoDir, path, reason string) error

Lock prevents `git worktree prune` from removing this worktree.

func Remove

func Remove(repoDir, path string) error

Remove removes a worktree (without --force; caller can opt in via RemoveForce).

func RemoveForce

func RemoveForce(repoDir, path string) error

RemoveForce removes the worktree even if it has uncommitted changes.

func Unlock

func Unlock(repoDir, path string) error

Unlock reverses Lock.

Types

type AcquireOptions

type AcquireOptions struct {
	Branch string
	// ForceFresh replaces a clean, verified allocation only; dirty files are preserved.
	ForceFresh bool
	LockReason string
}

type ManagedTree

type ManagedTree struct {
	TaskID    string
	Path      string
	Branch    string
	CreatedAt time.Time
	// GitDir binds the allocation to Git's administrative identity, not merely a path.
	GitDir       string
	AllocationID string
	LockReason   string
}

type Manager

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

func NewManager

func NewManager(repoDir, subDir string) *Manager

func (*Manager) Acquire

func (m *Manager) Acquire(task string, opts AcquireOptions) (*ManagedTree, error)

func (*Manager) Get

func (m *Manager) Get(task string) *ManagedTree

func (*Manager) List

func (m *Manager) List() []*ManagedTree

func (*Manager) Reclaim

func (m *Manager) Reclaim() error

func (*Manager) Release

func (m *Manager) Release(task string, opts ReleaseOptions) error

type ReleaseOptions

type ReleaseOptions struct {
	DeleteBranch bool
	// Force is retained for compatibility. Managed cleanup never discards dirty work.
	Force bool
}

type Worktree

type Worktree struct {
	Path       string
	HEAD       string
	Branch     string
	Bare       bool
	Detached   bool
	Locked     bool
	LockReason string
	Prunable   bool
}

Worktree describes one entry from `git worktree list --porcelain`.

func List

func List(repoDir string) ([]Worktree, error)

List parses `git worktree list --porcelain` from repoDir.

Jump to

Keyboard shortcuts

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