Documentation
¶
Overview ¶
Package stack owns everything about a worktree's docker stack: how it is named, which ports it gets, and how it goes up and down.
Index ¶
- Constants
- func AllocatePort(defaultPort, index, stride, projectOffset int) (int, error)
- func PortsOverride(allocations []Allocation) string
- func ProjectName(repoName string, index int, branch string) string
- func ProjectPrefix(repoName string, index int) string
- func Stride(projectDir string) int
- func WorktreesRoot(repoDir string) string
- func WriteEnvOverrides(worktreeDir string, allocations []Allocation) error
- type Allocation
- type Client
- func (c *Client) Down(ctx context.Context, project, worktreeDir string) error
- func (c *Client) FindByBranch(ctx context.Context, branch string) (Worktree, error)
- func (c *Client) Up(ctx context.Context, project, worktreeDir string, files []string) error
- func (c *Client) Worktrees(ctx context.Context) ([]Worktree, error)
- type Worktree
Constants ¶
const DefaultStride = 1
Variables ¶
This section is empty.
Functions ¶
func AllocatePort ¶
func PortsOverride ¶
func PortsOverride(allocations []Allocation) string
PortsOverride rebases the ports a project wrote as literals, which no environment variable can reach and which would otherwise publish the very ports the main stack holds. Compose appends `ports` when merging, so the list has to be replaced with !override, restating every port of that service.
func ProjectName ¶
ProjectName is the compose project wtc gives a worktree. Mirrors its composeProjectName/sanitize pair, which is the only way to address that stack's containers and volumes from the outside.
func ProjectPrefix ¶ added in v0.2.0
ProjectPrefix is what every compose project of a worktree at this index starts with, whatever its branch. It is how leftovers of a removed worktree are spotted before the index is handed to a new one.
func Stride ¶
Stride reads the project's port stride, from .wtcrc.json when present so an existing setup keeps working untouched.
func WorktreesRoot ¶ added in v0.4.6
WorktreesRoot is where a repository's wtm worktrees live. What git lists outside it, a `claude -w` worktree under .claude/worktrees or a manual `git worktree add` anywhere else, has none of what every wtm command needs: no stable index, no provisioned .env, no stack.
func WriteEnvOverrides ¶
func WriteEnvOverrides(worktreeDir string, allocations []Allocation) error
WriteEnvOverrides rewrites the port block of the worktree's .env in place. docker compose reads that file from the project directory on its own, which is how the rebased ports reach the containers.
Types ¶
type Allocation ¶
func Allocate ¶
func Allocate(services []compose.ServicePort, index, stride, projectOffset int) ([]Allocation, error)
Allocate rebases every published port of the compose file, whether it is written as a variable or as a literal. A literal cannot be overridden through the environment, so it is rebased through a generated compose file instead; see PortsOverride.
type Client ¶
func (*Client) FindByBranch ¶
type Worktree ¶
type Worktree struct {
Index int
Pos int
Path string
Branch string
// git refuses to remove a locked worktree even with one --force. A lock can
// carry no reason, so the flag cannot be inferred from LockReason.
Locked bool
LockReason string
}
Worktree carries two very different numbers. Index is the stable one the ports and the compose project name derive from, filled by internal/index, not here. Pos is where git listed the worktree, which resorts alphabetically, so it is only a first-guess hint for that resolver.