Skip to main content

Workspace

Struct Workspace 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn config(&self) -> &Config

The merged configuration (defaults, global config.toml, repo .wt.toml).

Source

pub fn is_bare(&self) -> bool

Whether the primary repository is bare.

Source

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).

Source

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.

Source

pub fn read_meta(&self, branch: &str) -> Result<WtMeta>

Reads the wt.* metadata recorded for branch.

Source

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.

Source

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.

Source

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).

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more