Skip to main content

Module worktree

Module worktree 

Source
Expand description

The worktree operation layer (issue #95).

Workspace is the public, stateless surface: discovered from a directory, it enumerates, creates, and removes worktrees and reads their wt.* metadata with no prompting, no terminal, and no Cx — outcomes and warnings are returned as data and the caller decides how (or whether) to present them. The wt CLI and TUI are thin interactive wrappers over this module; embedders (karet) call it directly and must resolve worktree paths through it rather than reimplementing the .wt.toml layout rules.

rows is the crate-internal row assembly on top: enriched listing rows, worktree-less branch rows (issue #47), sorting, and the remove/prune guard evaluation shared by the CLI and TUI.

Every type reachable through the public API is re-exported here. A doctest compiles as its own crate, so this one fails exactly when an embedder could not name what CreatedWorktree and RemovedWorktree hand back — which a crate-internal test cannot catch, since service is visible in-crate:

use wt::worktree::{
    CreatedWorktree, HookOutcome, RemovedWorktree, SubmoduleSeeding, SubmodulesOutcome,
};

fn inspect(created: &CreatedWorktree, removed: &RemovedWorktree) {
    let _: &SubmoduleSeeding = &created.submodule_seeding;
    let _: &SubmodulesOutcome = &created.submodules;
    let _: &HookOutcome = &created.post_create;
    let _: &HookOutcome = &removed.pre_remove;
}

Re-exports§

pub use crate::config::wtconfig::SCHEMA_VERSION;

Structs§

CreateOptions
Options for Workspace::create.
CreatedWorktree
The outcome of Workspace::create.
MetaUpdate
A wt.<branch>.* metadata update for Workspace::write_meta: every Some field is written and every None field leaves the recorded value untouched, so a caller refreshing one key cannot clobber the rest.
RemoveOptions
Options for Workspace::remove. The worktree-removal force is decoupled from the branch-deletion force: the TUI confirm dialog forces removal of a dirty worktree without ever force-deleting an unmerged branch (spec §10/§12).
RemovedWorktree
The outcome of Workspace::remove.
RepoLock
A held advisory repository lock (issue #99): while alive, no other wt (or embedder going through this library) can mutate worktrees or wt.* metadata in the repository. Released on drop.
SubmoduleSeeding
What the local-mirror seeding step managed to do, as counts plus the failures. Purely informational: seeding is always followed by a stock git submodule update --init --recursive, so a non-empty failed here does not mean the submodules are unpopulated.
Workspace
A discovered repository with its resolved configuration and environment snapshot: the entry point of the stateless worktree API.

Enums§

HookOutcome
How a hook invocation went, reported as data (the service never prints).
SubmodulesOutcome
How the post-create submodule initialization went.