# WorktreeSet

> For the complete documentation index, see [llms.txt](https://docs-stg.ringleader.dev/llms.txt).


> A WorktreeSet is a directory on one workstation that holds a git worktree of each of up to eight sources, all on one branch.


A **WorktreeSet** is a directory on one workstation that holds a git worktree of each of one to
eight of the workstation's sources, all on one branch. Terminal sessions and agent sessions name a
set and start in its first tree. This page lists the fields of the kind.
[Worktree sets](https://docs-stg.ringleader.dev/workstations/sessions/worktree-sets/) explains where the trees
live and how to use a set.

The kind is in the `workstations.ringleader.dev/v1` API group. A set belongs to the person who
creates it. A member manages their own sets, and an administrator of the namespace manages all of
the namespace's sets. A set has no `share` command.

## Minimal example

```yaml
apiVersion: workstations.ringleader.dev/v1
kind: WorktreeSet
metadata:
  name: tls-floor
  namespace: acme-dev
spec:
  workstationRef: {name: my-box}
  path: sessions/ringleader/tls-floor
  branch: fix/tls-floor
  sources: [ringleader, infra]
```

Apply a file with `rl apply -f`, or create a set with
[`rl worktreeset create`](https://docs-stg.ringleader.dev/reference/cli/commands/terminal-sessions/#rl-worktreeset-create-name).

## Spec fields

`workstationRef`, `path`, `branch` and `sources` are required, and `deletionPolicy` is optional.
Only `sources` and `deletionPolicy` can change after you create the set.

| Field | Type | Description |
|-------|------|-------------|
| `workstationRef` | `object` | `{name}`: the workstation that holds the trees. Fixed after create. |
| `path` | `string` | The directory that holds the trees, absolute or relative to the login user's home. At most 512 bytes of letters, digits and `_ . / @ + -`. Write a home path without `~`. Each tree is at `<path>/<source>`. Fixed after create. |
| `branch` | `string` | The branch every tree is on, used exactly as written. At most 256 bytes of letters, digits and `_ . / -`, and a name that git accepts. Fixed after create. |
| `sources` | `[]string` | One to eight names of the workstation's sources, which are the `sources[].name` entries of its configuration. No name repeats, and none contains `/` or is `.` or `..`. The first source is where a session starts, so the order matters. |
| `deletionPolicy` | `string` | Whether Ringleader deletes the set when sessions stop naming it: `DeleteWhenUnused` or `Retain`. With `DeleteWhenUnused`, Ringleader deletes the set after no session has named it for 10 minutes. With `Retain`, the set stays until you delete it. A set made with `rl worktreeset create` has no value, and stays until you delete it too. |

Changing a fixed field is rejected with a message that says the field is fixed when a worktree set
is created, and tells you to create a new set.

When the desktop app or the web console creates a set for a new session, it gives the set
`deletionPolicy: DeleteWhenUnused`. Ringleader then deletes the set after no session has named it
for 10 minutes. To keep the set, change the field to `Retain`, as
[Keep a set that the app created](https://docs-stg.ringleader.dev/workstations/sessions/worktree-sets/#keep-a-set-that-the-app-created)
shows.

## Status fields

The workstation reports these. They are read-only.

| Field | Type | Description |
|-------|------|-------------|
| `phase` | `string` | `Pending`, `Ready` or `Stopped`. See [Phases](#phases). |
| `message` | `string` | A sentence that says what the set waits for, or that it is ready. |
| `worktrees` | `[]object` | One entry for each source, in the order of `spec.sources`. See [Tree fields](#tree-fields). |

A WorktreeSet reports no `conditions` list. Read the phase with `rl worktreeset get`, and the
trees with `rl worktreeset get <name> -o yaml`.

## Phases

| Phase | Meaning |
|-------|---------|
| `Pending` | At least one tree is not made. `status.message` says why, such as `Waiting for <workstation> to make this set's trees.` |
| `Ready` | Every tree is made: `Every tree of this set is made on <workstation>.` |
| `Stopped` | The owner no longer holds the workstation, because a [pool lease](https://docs-stg.ringleader.dev/reference/resources/workstationpool/#lease-phases) ended. The reason is `LeaseEnded`. |

A `Pending` set can say `Something on <workstation> is in the way of one of this set's trees`, such
as its branch being checked out somewhere else. Change the branch or the path, or remove what is in
the way.

### Tree fields

| Field | Type | Description |
|-------|------|-------------|
| `source` | `string` | The source the tree is a worktree of. |
| `path` | `string` | The tree's directory on the workstation. |
| `branch` | `string` | The branch the tree is on. |
| `state` | `string` | `made` or `waiting`. |
| `class` | `string` | Why a tree waits, such as `refused` for a tree that cannot be made as written. |

## Refusals

Ringleader checks a set when you create or apply it, and rejects it with a message that names the
field:

| Message | Fix |
|---------|-----|
| `spec.path: is "~/x", which holds a character a source path cannot ...` | Write a home path without `~`. |
| `spec.branch: is "fix.lock", which git cannot use as a branch name ...` | Choose a name git accepts. A name ending in `.lock` is not. |
| `spec.sources[1]: repeats the source "a": a set holds one tree of each source` | Name each source once. |

Each source must also be declared on the workstation, or Ringleader rejects the set. Deleting a
set is refused while a terminal session names it, or while an agent session that names it is
running. The message names up to five sessions.

## Next steps

- [Worktree sets](https://docs-stg.ringleader.dev/workstations/sessions/worktree-sets/): where the trees live,
  what makes one wait and what keeps one.
- [Terminal sessions](https://docs-stg.ringleader.dev/workstations/sessions/terminal-sessions/): sessions whose
  panes start in a set.
- [TerminalSession and LocalTerminalSession](https://docs-stg.ringleader.dev/reference/resources/terminalsession/):
  the `worktreeSetRef` field.
- [Terminal session and worktree set commands](https://docs-stg.ringleader.dev/reference/cli/commands/terminal-sessions/):
  every command and flag.
- [Workstation](https://docs-stg.ringleader.dev/reference/resources/workstation/): the workstation and its sources.

