worktree

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package worktree manages isolated git worktrees by shelling out to `git worktree`. The Manager interface is consumed by the cli/app layers; Git is the only implementation.

Safety invariant: Shepherd never performs a mutating operation against the main working tree. RunInWorktree and Remove refuse it, and Remove additionally refuses any path outside the configured worktrees root.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecResult

type ExecResult struct {
	Stdout   string        `json:"stdout"`
	Stderr   string        `json:"stderr"`
	ExitCode int           `json:"exit_code"`
	Duration time.Duration `json:"duration"`
}

ExecResult is the captured outcome of a command run in (or for) a worktree.

type Git

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

Git implements Manager over the git CLI.

func NewGit

func NewGit(opts Options, log *zerolog.Logger) *Git

NewGit builds a Git manager. A nil logger is replaced with a no-op logger.

func (*Git) Create

func (g *Git) Create(ctx context.Context, task domain.Task, base string) (domain.Worktree, error)

Create makes a new worktree+branch for task, branched from base (or the configured default / HEAD). On a name/branch collision it appends a short unique suffix.

func (*Git) Get

func (g *Git) Get(ctx context.Context, ref string) (domain.Worktree, error)

func (*Git) List

func (g *Git) List(ctx context.Context) ([]domain.Worktree, error)

func (*Git) Prune

func (g *Git) Prune(ctx context.Context, removeBranches bool) ([]domain.Worktree, error)

func (*Git) Remove

func (g *Git) Remove(ctx context.Context, wt domain.Worktree, force bool) error

func (*Git) RunInWorktree

func (g *Git) RunInWorktree(ctx context.Context, wt domain.Worktree, name string, args ...string) (ExecResult, error)

type Manager

type Manager interface {
	Create(ctx context.Context, task domain.Task, base string) (domain.Worktree, error)
	List(ctx context.Context) ([]domain.Worktree, error)
	Get(ctx context.Context, ref string) (domain.Worktree, error)
	RunInWorktree(ctx context.Context, wt domain.Worktree, name string, args ...string) (ExecResult, error)
	Remove(ctx context.Context, wt domain.Worktree, force bool) error
	Prune(ctx context.Context, removeBranches bool) ([]domain.Worktree, error)
}

Manager creates and manages git worktrees.

type Options

type Options struct {
	RepoRoot     string // absolute main work tree
	Root         string // absolute worktrees root
	NameTemplate string
	BranchPrefix string
	DefaultBase  string // base ref when none is given (empty => HEAD)
}

Options configures a Git manager. The app layer maps config into these so the worktree package stays independent of the config schema.

Jump to

Keyboard shortcuts

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