Documentation
¶
Overview ¶
Package worktree creates, starts, stops and removes project worktrees, and drives the docker stack that goes with each one.
Index ¶
- Constants
- func Adopt(ctx context.Context, o Options) error
- func Create(ctx context.Context, o Options) error
- func Exec(ctx context.Context, o Options, service string, command []string) error
- func Path(ctx context.Context, o Options) (string, error)
- func Ports(ctx context.Context, o Options) ([]string, error)
- func Remove(ctx context.Context, o Options) error
- func Run(ctx context.Context, o Options, command []string) error
- func Start(ctx context.Context, o Options) error
- func Stop(ctx context.Context, o Options) error
- type Entry
- type Options
Constants ¶
const StatusAdoptable = "adoptable"
StatusAdoptable is shown for a worktree git lists and wtm has not adopted. It stands where up and down would: such a worktree has no index, hence no stack of its own to be up or down.
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 Adopt ¶ added in v0.10.0
Adopt gives a worktree wtm did not create everything it gives one it did: a stable index, provisioned .env files and compose overrides, a restored snapshot and a stack. It stays where it is: an agent may be working in it.
func Exec ¶
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 ¶
Path returns the worktree directory, so a shell can compose with it: `cd $(wtm path feat/x)`.
func Ports ¶ added in v0.19.0
Ports returns the addresses `start` prints, for a process handed a stack it did not start. The profile it was started with is not recorded, so every published port is listed.
func Run ¶
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.
Types ¶
type Entry ¶
type Entry struct {
stack.Worktree
// Status is "up", "down", "adoptable" for a worktree wtm has not adopted,
// or "-" when docker could not be reached.
Status string
}
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 container. Shell lines, never persisted.
RunAfter string
ExecAfter string
// Profile is the stack profile this start brings up, empty for the whole
// stack. Deliberately not remembered: a worktree narrowed months ago, with
// nothing on screen saying so, is a puzzle, and naming it again is one word.
Profile string
Force bool // remove despite uncommitted tracked changes
// Inferred says nobody named this branch: `wtm create` releasing a vanished
// worktree's index acts on a guess, so it refuses to take down a stack that
// still runs. A branch somebody typed or confirmed sweeps what it was asked to.
Inferred bool
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. Its only caller is the memory advisory, an average over the
// running stacks: worth a question, never worth failing a create on.
Confirm func(question string) bool
// BaseFromHere says Base came from `create --from-here` rather than from the
// project or the command line. An existing branch is checked out as-is and
// ignores the base, so that combination is refused rather than logged.
BaseFromHere bool
// RenameTo is the name an adopted branch takes. Adoption is the only
// moment a rename is free: the compose project name carries the branch, so
// renaming once a stack exists orphans the stack it names.
RenameTo string
// ConfirmAdopt asks before writing into a worktree wtm did not create. It
// is deliberately not Confirm: --ignore-memory answers the memory advisory
// alone, and must not also wave through a write into somebody's checkout.
ConfirmAdopt func(question string) bool
}