wt/worktree/mod.rs
1//! The worktree operation layer (issue #95).
2//!
3//! [`Workspace`] is the public, stateless surface: discovered from a
4//! directory, it enumerates, creates, and removes worktrees and reads their
5//! `wt.*` metadata with **no prompting, no terminal, and no
6//! [`Cx`](crate::cx::Cx)** — outcomes and warnings are returned as data and the
7//! caller decides how (or whether) to present them. The `wt` CLI and TUI are
8//! thin interactive wrappers over this module; embedders (karet) call it
9//! directly and must resolve worktree paths through it rather than
10//! reimplementing the `.wt.toml` layout rules.
11//!
12//! `rows` is the crate-internal row assembly on top: enriched listing rows,
13//! worktree-less branch rows (issue #47), sorting, and the remove/prune guard
14//! evaluation shared by the CLI and TUI.
15//!
16//! Every type reachable through the public API is re-exported here. A doctest
17//! compiles as its own crate, so this one fails exactly when an embedder could
18//! not name what [`CreatedWorktree`] and [`RemovedWorktree`] hand back — which
19//! a crate-internal test cannot catch, since `service` is visible in-crate:
20//!
21//! ```
22//! use wt::worktree::{
23//! CreatedWorktree, HookOutcome, RemovedWorktree, SubmoduleSeeding, SubmodulesOutcome,
24//! };
25//!
26//! fn inspect(created: &CreatedWorktree, removed: &RemovedWorktree) {
27//! let _: &SubmoduleSeeding = &created.submodule_seeding;
28//! let _: &SubmodulesOutcome = &created.submodules;
29//! let _: &HookOutcome = &created.post_create;
30//! let _: &HookOutcome = &removed.pre_remove;
31//! }
32//! ```
33
34pub(crate) mod materialize;
35pub(crate) mod rows;
36mod service;
37
38pub use crate::config::wtconfig::SCHEMA_VERSION;
39// The row/guard helpers and the parts-based service entry points are how the
40// command handlers and the TUI drive this module; the core library's public
41// surface is the `Workspace` API and the re-exported schema/lock types.
42#[cfg(feature = "cli")]
43pub(crate) use rows::{
44 build_rows, build_worktrees, enrich_worktree, enumerate_worktrees, guard_status, sort_worktrees,
45};
46// The synchronous branch-row listing and base-first sort exist for the TUI
47// (issue #47).
48#[cfg(feature = "tui")]
49pub(crate) use rows::{enumerate_rows, sort_worktrees_base_first};
50pub use service::{
51 CreateOptions, CreatedWorktree, HookOutcome, MetaUpdate, RemoveOptions, RemovedWorktree,
52 RepoLock, SubmoduleSeeding, SubmodulesOutcome, Workspace,
53};
54#[cfg(feature = "cli")]
55pub(crate) use service::{
56 WorkspaceParts, apply_meta, create_in, lock_repo, preview_target, remove_in, resolve_base,
57 resolve_target, rollback_worktree, same_path,
58};