worktrees

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean(ctx context.Context, options Options, maxAge time.Duration) error

Clean prunes any zero-owned git worktrees older than maxAge to prevent disk space leaks.

func DefaultBaseDir

func DefaultBaseDir(env map[string]string) (string, error)

func Release

func Release(ctx context.Context, options Options, path string) error

Release unlocks a worktree that Prepare locked, via `git worktree unlock`, making it eligible for Clean's staleness check again. Zero itself only knows a worktree's use is over when its own process created it and is now exiting (zero exec --worktree calls this via defer); zero worktrees prepare hands the path to an external caller with no defined end-of-life, so that caller must run `zero worktrees release <path>` itself once done. Until it does, the worktree stays locked and Clean will never touch it, which is the safe default over silently guessing at liveness from mtimes.

Types

type CommandResult

type CommandResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

type GitRunner

type GitRunner func(context.Context, string, ...string) (CommandResult, error)

type Options

type Options struct {
	Cwd     string
	Name    string
	BaseDir string
	Env     map[string]string
	Now     func() time.Time
	RunGit  GitRunner
	// LeasePID, when positive, records the owning process in the worktree
	// lock reason. A lease carrying a PID is recoverable: if that process
	// dies without releasing (SIGKILL, crash, power loss), Clean can expire
	// the lease instead of skipping the locked worktree forever. Callers
	// whose worktree outlives their process (zero worktrees prepare hands
	// the path to an external owner) leave it zero for a persistent lock
	// that only an explicit release clears.
	LeasePID int
}

type Result

type Result struct {
	Name         string `json:"name"`
	Path         string `json:"path"`
	RepoRoot     string `json:"repoRoot"`
	SourceBranch string `json:"sourceBranch,omitempty"`
	SourceCommit string `json:"sourceCommit,omitempty"`
	Reused       bool   `json:"reused"`
	// LockAcquired reports whether this Prepare call took the worktree lock.
	// It is false when a reused worktree was already locked by another live
	// caller; releasing that lease is that caller's responsibility, not ours.
	LockAcquired bool `json:"lockAcquired"`
}

func Prepare

func Prepare(ctx context.Context, options Options) (Result, error)

Jump to

Keyboard shortcuts

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