worktree

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 20 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

Overview

Package worktree creates, starts, stops and removes project worktrees, and drives the docker stack that goes with each one.

Index

Constants

View Source
const StatusUnknown = "-"

StatusUnknown is shown when docker did not answer in time. A listing is a read-only question about git and must never hang on an unresponsive daemon.

Variables

This section is empty.

Functions

func Create

func Create(ctx context.Context, o Options) error

func Exec

func Exec(ctx context.Context, o Options, service string, command []string) error

Exec runs a command inside the worktree's application container. Doing it by hand means knowing the compose project name wtm derives, which is internal knowledge no user should need.

func Path

func Path(ctx context.Context, o Options) (string, error)

Path returns the worktree directory, so a shell can compose with it: `cd $(wtm path feat/x)`.

func Remove

func Remove(ctx context.Context, o Options) error

Remove stops the stack then removes the worktree, keeping the local branch.

func Run

func Run(ctx context.Context, o Options, command []string) error

Run is the counterpart of Exec: it stays on the machine, with the worktree as working directory, for editors, agents and anything else working on the files rather than in the running application.

func Start

func Start(ctx context.Context, o Options) error

Start brings an existing worktree's stack back up. Without it, restarting a stopped worktree means calling docker compose with the index wtm derives, which is exactly the internal knowledge this tool exists to hide.

func Stop

func Stop(ctx context.Context, o Options) error

Stop takes the stack down and leaves the worktree in place.

Types

type Entry

type Entry struct {
	stack.Worktree
	// Status is "up", "down", or "-" when docker could not be reached.
	Status string
}

func List

func List(ctx context.Context, o Options) ([]Entry, error)

type Options

type Options struct {
	Name         string // project name in the registry
	Project      config.Project
	Branch       string
	Base         string
	NoStart      bool
	NoPostCreate bool // skip the project's post_create on this create
	// RunAfter and ExecAfter are the commands of `create --run` and
	// `create --exec`, played once the create is done: the first on the host
	// from the worktree, the second in the application container. Both are
	// shell lines and never persisted, unlike post_create.
	RunAfter   string
	ExecAfter  string
	Force      bool // remove despite uncommitted tracked changes
	BackupsDir string
	Runner     execx.Runner
	Out        io.Writer
	Stack      *stack.Client
	Resolver   *index.Resolver // resolves and records each branch's stable index
	// Confirm asks a yes-or-no question, and is nil when nobody is there to
	// answer. The memory advisory is its only caller: it rests on an average
	// over the running stacks, which predicts neither a light stack nor a heavy
	// one, so it is worth a question to a person and never worth failing the
	// create of a script or an agent.
	Confirm func(question string) bool
}

Jump to

Keyboard shortcuts

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