pub struct Manager { /* private fields */ }Expand description
Core worktree lifecycle manager. Entry point for all iso-code operations.
Manager is Send but not Sync — the circuit-breaker counter uses
Cell for zero-overhead single-threaded access. To share a Manager
across threads, wrap it in Arc<Mutex<Manager>>.
Implementations§
Source§impl Manager
impl Manager
Sourcepub fn new(
repo_root: impl AsRef<Path>,
config: Config,
) -> Result<Self, WorktreeError>
pub fn new( repo_root: impl AsRef<Path>, config: Config, ) -> Result<Self, WorktreeError>
Construct a Manager for the given repository root.
Construction performs, in order:
- Validate
git --versionis at least 2.20. - Canonicalize
repo_rootand detectGitCapabilities. - Ensure
.git/iso-code/exists and initializestate.jsonon first use. - Scan for orphaned worktrees (non-fatal; emits warnings only).
- Sweep expired port leases.
Sourcepub fn with_adapter(
repo_root: impl AsRef<Path>,
config: Config,
adapter: Option<Box<dyn EcosystemAdapter>>,
) -> Result<Self, WorktreeError>
pub fn with_adapter( repo_root: impl AsRef<Path>, config: Config, adapter: Option<Box<dyn EcosystemAdapter>>, ) -> Result<Self, WorktreeError>
Construct a Manager with an explicit EcosystemAdapter.
The adapter’s setup() method will be called after create() and attach()
when the corresponding options have setup = true.
Sourcepub fn git_capabilities(&self) -> &GitCapabilities
pub fn git_capabilities(&self) -> &GitCapabilities
Return the detected git capabilities.
Sourcepub fn list(&self) -> Result<Vec<WorktreeHandle>, WorktreeError>
pub fn list(&self) -> Result<Vec<WorktreeHandle>, WorktreeError>
List all worktrees, reconciling git porcelain output with state.json.
Reconciliation runs on every call:
- Run
git worktree list --porcelain. - Enrich each handle with state.json metadata (created_at, session_uuid, …).
- Move state entries missing from git output to
stale_worktrees. - Purge stale entries whose
expires_athas passed. - Sweep port leases: drop dead holders and expired leases.
Sourcepub fn create(
&self,
branch: impl Into<String>,
path: impl AsRef<Path>,
options: CreateOptions,
) -> Result<(WorktreeHandle, CopyOutcome), WorktreeError>
pub fn create( &self, branch: impl Into<String>, path: impl AsRef<Path>, options: CreateOptions, ) -> Result<(WorktreeHandle, CopyOutcome), WorktreeError>
Create a new managed worktree.
The sequence is ordered and must not be reshuffled:
- Run every pre-create guard.
- Write a
Creatingentry to state.json. - Run
git worktree add. - Post-create git-crypt verification.
- Run
EcosystemAdapter::setupif the caller requested it. - Transition the entry to
Active(orLockedifoptions.lock).
If any step after git worktree add fails, the worktree is force-removed
with git worktree remove --force and the Creating entry is cleared
before the error propagates.
Sourcepub fn attach(
&self,
path: impl AsRef<Path>,
options: AttachOptions,
) -> Result<WorktreeHandle, WorktreeError>
pub fn attach( &self, path: impl AsRef<Path>, options: AttachOptions, ) -> Result<WorktreeHandle, WorktreeError>
Attach an existing worktree (already in git’s registry) under iso-code management.
Never calls git worktree add — the worktree must already appear in
git worktree list --porcelain. If the path is already tracked in
active_worktrees the existing handle is returned (idempotent). If a
matching entry exists in stale_worktrees, its port and session_uuid
are recovered.
Sourcepub fn delete(
&self,
handle: &WorktreeHandle,
options: DeleteOptions,
) -> Result<(), WorktreeError>
pub fn delete( &self, handle: &WorktreeHandle, options: DeleteOptions, ) -> Result<(), WorktreeError>
Delete a managed worktree.
Ordered pre-flight checks (each may abort the delete):
- Refuse to delete the caller’s current working directory.
- Reject a dirty working tree unless
options.force_dirty. - Reject unmerged commits unless
options.force. - Reject worktrees held by
git worktree lock.
Once the checks pass, the entry transitions to Deleting, git worktree remove runs, and the entry is finally cleared from state.json.
Sourcepub fn gc(&self, options: GcOptions) -> Result<GcReport, WorktreeError>
pub fn gc(&self, options: GcOptions) -> Result<GcReport, WorktreeError>
Garbage collect orphaned and stale worktrees.
The default GcOptions is dry-run. Locked worktrees are always
preserved, regardless of options.force. Evicted entries are moved to
stale_worktrees so their metadata can be recovered — gc() never
silently drops state.
Sourcepub fn touch(&self, branch: &str) -> Result<(), WorktreeError>
pub fn touch(&self, branch: &str) -> Result<(), WorktreeError>
Mark branch as recently active by bumping its last_activity
timestamp in state.json. Callers wrap user-visible actions (shell
into the worktree, run a build, etc.) with this so gc() can tell
“idle since creation” apart from “recently used.” Returns
InvalidStateTransition-style StateCorrupted if the branch isn’t
tracked in active_worktrees.
Sourcepub fn port_lease(&self, branch: &str) -> Option<PortLease>
pub fn port_lease(&self, branch: &str) -> Option<PortLease>
Return the active port lease for a branch, if any.
Sourcepub fn allocate_port(
&self,
branch: &str,
session_uuid: &str,
) -> Result<u16, WorktreeError>
pub fn allocate_port( &self, branch: &str, session_uuid: &str, ) -> Result<u16, WorktreeError>
Allocate a port lease for a branch without creating a worktree.
Sourcepub fn disk_usage(&self, path: &Path) -> u64
pub fn disk_usage(&self, path: &Path) -> u64
Return the on-disk byte size of a worktree tree, skipping the .git/
subtree and deduplicating hardlinks on Unix.
Sourcepub fn release_port(&self, branch: &str) -> Result<(), WorktreeError>
pub fn release_port(&self, branch: &str) -> Result<(), WorktreeError>
Release a port lease explicitly.
Sourcepub fn renew_port_lease(&self, branch: &str) -> Result<(), WorktreeError>
pub fn renew_port_lease(&self, branch: &str) -> Result<(), WorktreeError>
Extend an active port lease’s TTL by another 8 hours from now.
Callers running a long-lived dev server invoke this roughly every
TTL/3 to keep the lease from expiring mid-session. Returns
StateCorrupted if the branch has no active lease — expired leases
must be re-allocated via Manager::allocate_port rather than
renewed, since their port may have been reassigned.
Auto Trait Implementations§
impl !Freeze for Manager
impl !RefUnwindSafe for Manager
impl Send for Manager
impl !Sync for Manager
impl Unpin for Manager
impl UnsafeUnpin for Manager
impl !UnwindSafe for Manager
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> 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