worktree

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 12 Imported by: ? 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

View Source
var DetectPrimaryCheckoutFunc = DetectPrimaryCheckout

DetectPrimaryCheckoutFunc is the function used to detect primary checkout. It is a variable to allow test injection.

Functions

func CheckCWDSafe

func CheckCWDSafe(cwd, root, name string) error

CheckCWDSafe returns an error if cwd is inside the named worktree.

func DetectPkgManager

func DetectPkgManager(dir string) string

DetectPkgManager returns the package manager name based on lock files in dir.

func DetectPrimaryCheckout

func DetectPrimaryCheckout() (bool, error)

DetectPrimaryCheckout resolves the current git dir and classifies checkout type.

func InstallArgs

func InstallArgs(pm string) (bin string, args []string)

InstallArgs returns the binary and arguments for installing deps.

func IsCWDInsideWorktree

func IsCWDInsideWorktree(cwd, wtPath string) bool

IsCWDInsideWorktree reports whether cwd is at or below wtPath.

func IsPrimaryCheckout

func IsPrimaryCheckout(absGitDir string) bool

IsPrimaryCheckout reports whether absGitDir points at the repo's primary checkout.

func IsRealWorktree

func IsRealWorktree(dir string) bool

IsRealWorktree reports whether dir looks like a valid git worktree (has a .git file or directory).

func RunHook

func RunHook(r io.Reader, w io.Writer) error

RunHook reads a PreToolUse JSON payload from r, checks the command, and writes a deny decision to w if the command is blocked. Returns nil on success (including when the command is allowed and nothing is written).

func ValidateLinkedCheckout

func ValidateLinkedCheckout(path string) (string, error)

ValidateLinkedCheckout resolves and validates a checkout path. It enforces that the path exists, is a git checkout, and is NOT a primary checkout (".git"). This structurally requires linked worktrees for agent work.

func WorktreePath

func WorktreePath(root, name string) string

WorktreePath returns the on-disk path for a named worktree.

Types

type App

type App struct {
	Root              string
	CmdPrefix         string        // command prefix for user-facing messages (e.g., "noodle worktree")
	MergeLockTimeout  time.Duration // 0 uses defaultMergeLockTimeout
	IntegrationBranch string        // override for the integration branch; auto-discovered when empty
	Quiet             bool          // suppress stdout/stderr chatter for programmatic callers
}

App holds the resolved git root and provides worktree operations.

func NewApp

func NewApp() (*App, error)

NewApp discovers the git root from the current working directory.

func (*App) Cleanup

func (a *App) Cleanup(name string, opts ...CleanupOpts) error

Cleanup removes a worktree without merging.

func (*App) Create

func (a *App) Create(name string, opts ...CreateOpts) error

Create creates a new worktree and branch, symlinks local settings, and installs deps.

func (*App) Exec

func (a *App) Exec(name string, args []string) error

Exec runs a command inside the named worktree.

func (*App) HasUnmergedCommits

func (a *App) HasUnmergedCommits(name string) (bool, error)

func (*App) List

func (a *App) List() error

List shows all worktrees with merge status.

func (*App) Merge

func (a *App) Merge(name string, opts ...MergeOpts) error

Merge rebases the worktree branch onto a target branch, merges, and cleans up.

func (*App) MergeRemoteBranch

func (a *App) MergeRemoteBranch(branch string) error

func (*App) Prune

func (a *App) Prune() error

Prune removes merged worktrees automatically. A worktree is prune-safe when: 1) all branch commits are already represented on the integration branch by patch equivalence (`git cherry` has no "+" lines), and 2) the worktree has no uncommitted changes.

type CleanupOpts

type CleanupOpts struct {
	// Force removes the worktree even when unmerged commits exist.
	Force bool
}

CleanupOpts holds optional parameters for Cleanup.

type CreateOpts

type CreateOpts struct {
	// From is the branch or commit to base the new worktree on. Empty means HEAD.
	From string
}

CreateOpts holds optional parameters for Create.

type DiffResult

type DiffResult struct {
	Diff string `json:"diff"`
	Stat string `json:"stat"`
}

DiffResult holds the unified diff and diffstat for a worktree branch.

func DiffWorktree

func DiffWorktree(worktreePath string) (DiffResult, error)

DiffWorktree computes the diff between the worktree's branch HEAD and the base branch (auto-discovered from origin/HEAD, falling back to "main").

type ExitError

type ExitError struct {
	Code int
}

ExitError represents a process exit with a specific code.

func (*ExitError) Error

func (e *ExitError) Error() string

type HookContext

type HookContext struct {
	Cook              bool
	InPrimaryCheckout bool
}

HookContext captures session and checkout mode for command validation.

type HookDenial

type HookDenial struct {
	Reason string
}

HookDenial holds the reason a command was denied.

func CheckCommand

func CheckCommand(cmd string) *HookDenial

CheckCommand inspects a Bash command string and returns a denial if it matches a dangerous worktree pattern, or nil if the command is allowed.

func CheckCommandWithContext

func CheckCommandWithContext(cmd string, ctx HookContext) *HookDenial

CheckCommandWithContext applies static + contextual worktree safety checks.

type MergeConflictError

type MergeConflictError struct {
	Branch string
	Err    error
}

MergeConflictError marks deterministic git merge/rebase conflicts so callers can avoid retry loops and surface manual resolution paths.

func (*MergeConflictError) Error

func (e *MergeConflictError) Error() string

func (*MergeConflictError) Unwrap

func (e *MergeConflictError) Unwrap() error

type MergeOpts

type MergeOpts struct {
	// Into overrides the integration branch for this merge.
	Into string
}

MergeOpts holds optional parameters for Merge.

type WorktreeEntry

type WorktreeEntry struct {
	Name   string // display name (last path component or relative path under .worktrees/)
	Path   string // absolute on-disk path
	Branch string // branch name (empty for detached HEAD)
	Source string // "noodle", "claude", "cursor", or "other"
}

WorktreeEntry is a non-main worktree discovered from git metadata.

Jump to

Keyboard shortcuts

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