pub struct Workspace { /* private fields */ }Expand description
A discovered repository with its resolved configuration and environment snapshot: the entry point of the stateless worktree API.
Implementations§
Source§impl Workspace
impl Workspace
Sourcepub fn discover(dir: &Path, env: &Env, git: &dyn GitCli) -> Result<Workspace>
pub fn discover(dir: &Path, env: &Env, git: &dyn GitCli) -> Result<Workspace>
Discovers the repository containing dir, resolves the primary worktree
root, and loads the merged configuration. Returns
Error::NotInRepo when dir is not inside a Git repository.
Sourcepub fn lock(&self) -> Result<RepoLock>
pub fn lock(&self) -> Result<RepoLock>
Acquires the repository’s advisory mutation lock (issue #99). See
RepoLock for the holding rules.
Fails with Error::SchemaTooNew when the repository is stamped with a
metadata schema this build cannot interpret, re-read under the lock
(issue #106) — so the version an embedder validated at discovery is
still the version it holds the lock over.
Sourcepub fn root(&self) -> &Path
pub fn root(&self) -> &Path
The primary worktree root (or the repository path when bare). This is
the repo_root expected by the wtconfig write functions.
Sourcepub fn config(&self) -> &Config
pub fn config(&self) -> &Config
The merged configuration (defaults, global config.toml, repo
.wt.toml).
Sourcepub fn enumerate(&self, git: &dyn GitCli) -> Result<Vec<Worktree>>
pub fn enumerate(&self, git: &dyn GitCli) -> Result<Vec<Worktree>>
Enumerates worktrees with their synchronous fields only (path, branch, slug, current/main/missing/detached markers).
Sourcepub fn list(&self, git: &dyn GitCli) -> Result<Vec<Worktree>>
pub fn list(&self, git: &dyn GitCli) -> Result<Vec<Worktree>>
Enumerates worktrees fully enriched: dirty/untracked status,
ahead/behind, merge state, tip commits, and the cached PR metadata from
wt.* config.
Sourcepub fn read_meta(&self, branch: &str) -> Result<WtMeta>
pub fn read_meta(&self, branch: &str) -> Result<WtMeta>
Reads the wt.* metadata recorded for branch.
Sourcepub fn write_meta(
&self,
git: &dyn GitCli,
branch: &str,
update: &MetaUpdate,
) -> Result<()>
pub fn write_meta( &self, git: &dyn GitCli, branch: &str, update: &MetaUpdate, ) -> Result<()>
Writes the Some fields of update to branch’s wt.* metadata,
leaving every other recorded key alone (issue #95).
The whole update is applied under the advisory repository lock (issue
#99), so a concurrent writer never observes half a bundle — do not call
this while already holding a RepoLock. To make a read-check-write
sequence atomic, take Workspace::lock and drive the wtconfig
setters directly instead.
The schema gate is the lock’s (issue #106): nothing here runs ahead of it, so there is no separate check to keep in step.
Sourcepub fn clear_meta(&self, git: &dyn GitCli, branch: &str) -> Result<()>
pub fn clear_meta(&self, git: &dyn GitCli, branch: &str) -> Result<()>
Removes every wt.<branch>.* key, under the advisory repository lock.
A branch with no recorded metadata is not an error.
Sourcepub fn create(
&self,
git: &dyn GitCli,
hooks: &dyn HookRunner,
options: &CreateOptions,
) -> Result<CreatedWorktree>
pub fn create( &self, git: &dyn GitCli, hooks: &dyn HookRunner, options: &CreateOptions, ) -> Result<CreatedWorktree>
Creates (or reuses) a linked worktree per options: resolves the target
from the configured path template, creates the branch off its base when
needed, records wt.* metadata, runs the copy step, the post_create
hook, and (when requested) submodule initialization. Partial failures
before the hook are rolled back (spec §13).
Sourcepub fn remove(
&self,
git: &dyn GitCli,
hooks: &dyn HookRunner,
worktree: &Worktree,
options: &RemoveOptions,
) -> Result<RemovedWorktree>
pub fn remove( &self, git: &dyn GitCli, hooks: &dyn HookRunner, worktree: &Worktree, options: &RemoveOptions, ) -> Result<RemovedWorktree>
Removes worktree under options, enforcing the dirty/unpushed safety
guards (returning Error::RemoveGuarded when they block), running the
pre_remove hook, pruning a missing worktree, and deleting a
fully-merged wt-created branch per the configuration.
Auto Trait Implementations§
impl !Freeze for Workspace
impl !RefUnwindSafe for Workspace
impl !Sync for Workspace
impl !UnwindSafe for Workspace
impl Send for Workspace
impl Unpin for Workspace
impl UnsafeUnpin for Workspace
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more