Expand description
The branch-to-worktree topology: where every linked worktree of a repository belongs, derived from git and from nothing else, and everything that follows from it.
§The invariant
<parent>/<repo> the primary checkout, which hosts the trunk
<parent>/<repo>-wt/ the container, derived: parent + name + "-wt"
<parent>/<repo>-wt/<branch name> the one worktree of every non-trunk branchThe branch name is the relative path: feature/providers/openai-streaming lives at
<repo>-wt/feature/providers/openai-streaming, hierarchy preserved, nothing flattened,
nothing hashed, nothing registered. Git is the registry: the identity comes from the
common git directory, the worktrees from git worktree list --porcelain, the branches
from for-each-ref, and this module interprets them into one typed
RepositoryTopology that every surface renders.
§The architecture
git (common dir, worktree list, for-each-ref, status)
↓
RepositoryIdentity primary, current, container, trunk — from anywhere inside
↓
path::expected_path() container / branch name, proved to stay inside the container
↓
WorktreeService topology, status, guard, inspect, create, migrate, repair
↙ ↓ ↘
CLI capability git hooks → MCP, HTTP, OpenAPI, Swagger, the Cockpit, docsEvery surface is an adapter. Nothing outside this module derives a path, decides a standing, or judges whether a move is safe; a second implementation of any of those is the defect this module exists to prevent.
§Safety
Nothing here deletes a directory because its name looks right, and nothing here resets,
stashes, cleans or checks out anything. A migration moves a worktree with git worktree move, dirty state included, and proves with a fingerprint::WorktreeFingerprint
taken before and after that the branch, the commit, the index, the staged and unstaged
changes and the untracked files are the same on the other side. Every mutation holds one
repository-scoped lock::WorktreeLock, so two agents cannot half-register one path.
Re-exports§
pub use fingerprint::WorktreeFingerprint;pub use model::Severity;pub use uncommitted::OpenEpisode;pub use uncommitted::Threshold;pub use uncommitted::UncommittedReport;pub use uncommitted::UncommittedTallies;pub use uncommitted::UncommittedWorktree;pub use uncommitted::WorkStanding;
Modules§
- fingerprint
- The proof that a move lost nothing.
- state
- What git says about the state of a work tree and of every branch: uncommitted work from
status --porcelain, and every local branch with its upstream, its distance from it and the work tree holding it from onefor-each-ref. Nothing here fetches. - uncommitted
- Uncommitted work in the linked work trees, and whether anything still holds it (I1995).
Structs§
- Branch
Name - A branch name git would accept for
refs/heads/, whose components are therefore safe directory names. - Branch
State - One local branch, with or without a work tree.
- Branch
Trace - One branch that names an issue, with the commits it holds.
- Commit
Attribution - One commit and the contract it served, or the fact that none can be found.
- Commit
Ref - One commit, exactly as git names it. Nothing here is stored anywhere: the whole record is re-read from the object database on every call.
- Container
View - The container, as the topology reports it.
- Create
Report - What a create did.
- Create
Request - What to create.
- Dirty
State - Uncommitted work in a work tree, counted from
git status --porcelain. Untracked content counts: it is exactly what a careless move loses. - Guard
Verdict - What the guard decided, for a hook or a mutation that must not proceed out of place.
- Inspect
Report - One branch, inspected: where its work tree belongs and what is there.
- Issue
Trace - Everything git knows about one issue’s realisation.
- Migration
Options - What an apply may do beyond a rename.
- Migration
Plan - A migration, planned or applied.
- Migration
Step - One worktree to bring home.
- Remove
Report - What a remove did.
- Repair
Report - What a repair did.
- Repository
Identity - The repository a command is operating on, and every work tree git has registered for it.
- Repository
Topology - The whole topology: what
worktree list, the MCP resource, the HTTP route and the Cockpit all read. - Repository
View - The repository’s identity, as the topology reports it.
- Resolved
Path - A path as git names it and as the filesystem resolves it.
- Status
Report - The answer to “where am I, and is that where I belong”.
- Topology
Diagnostic - One thing wrong with, or worth knowing about, the topology.
- Topology
Tallies - How many work trees and branches are in each state.
- Trace
Report - The whole traceability answer: every issue git can say something about, and every commit of a stretch of the trunk with the contract it served or the fact that it has none.
- Trace
Tallies - The counts of one report.
- Tracer
- The reader. Opened from anywhere inside the repository; every question is answered by running git again, because the history changes outside this process.
- Trunk
- The trunk branch and how it was decided. Discovered state, never domain logic:
masterhere is a fact about this repository andmainwould be one about another. - Trunk
View - The trunk, as the topology reports it.
- Upstream
State - A branch’s upstream and how far the two have moved apart, from
for-each-refin one subprocess for every branch, never a fetch. - Worktree
Lock - The held lock. Dropping it releases it; a panic or an early return therefore cannot leave the repository locked.
- Worktree
Record - One work tree as git registered it.
- Worktree
Service - The repository’s worktrees, decided once.
- Worktree
State - One work tree, as the topology sees it.
Enums§
- Attribution
- What is known about the contract one commit served.
- Detail
- How much of each work tree’s state a topology reads.
- Diagnostic
Code - The stable machine name of everything that can be wrong with the topology. One code per condition, reused by the command line, the API, MCP, the Cockpit, the tests and the documentation; the prose beside a code is rendered from the typed state.
- Envrc
Approval - What became of the
.envrcof a worktree that was just created, found, or moved. - Hooks
Path - What became of the hooks directory of a worktree that was just created, found or moved.
- Integration
- How a branch stands to the trunk, which is what decides which commits are its own.
- Migration
Action - How a step moves its worktree.
- Standing
- Where a work tree stands against the topology.
- Start
Point - Where a new branch started, and why there.
- Step
Outcome - What became of a step.
- Trunk
Source - Where the trunk was learned from, in the order it is looked for.
- Worktree
Error - Everything that stops a worktree operation.
- Worktree
Kind - Whether a work tree is the repository’s own checkout or one linked to it.
Constants§
- CONTAINER_
SUFFIX - What is appended to the primary checkout’s directory name to name the container. The one place the convention is written; every path, document and message derives from it.
- EXIT_
INTERNAL - The exit code when git itself failed, or the topology cannot be read at all.
- EXIT_
MISSING - The exit code when the thing asked for does not exist.
- EXIT_
REFUSED - The exit code of a refusal: the operation is well-formed and the state of the tree says
no. The executable’s contract already spends
10on “contract unmet”. - SCHEMA
- The
schemaevery topology document carries.
Functions§
- carry_
hooks_ path - Bind
worktreeto the hooks directory of its own tree, when the repository tracks one and git would otherwise run another worktree’s. - container_
root - The container of a repository whose primary checkout is
primary: the checkout’s sibling, named after it withCONTAINER_SUFFIXappended. Never read from anywhere, never configured. - detached_
label - The label a detached worktree is shown under. Display only: a detached HEAD has no branch and therefore no canonical path, and nothing ever moves a worktree under this name.
- expected_
path - Where the worktree of
branchbelongs: the branch’s components under the container. - first_
merge - The first merge commit of a
rev-list --parents --reverse --ancestry-pathlisting, with its first parent. A listing whose first entry has one parent is a branch that reached the trunk without a merge of its own. - parse_
commit - Parse one commit line of
FORMAT. A line with fewer fields is not a commit. - parse_
issue_ refs - The refs of
textthat name one ofids, local branches first, each remote-tracking ref dropped when a local branch already stands for the same name. - parse_
porcelain - Parse porcelain records from attribute lines. The separator is the caller’s:
\nfor--porcelain,\0for--porcelain -z. A blank attribute ends a record. - parse_
porcelain_ nul - The same, from the NUL-separated form, where a path may contain a newline.
Type Aliases§
- Result
- The result of every worktree operation.