Skip to main content

WorktreeManager

Struct WorktreeManager 

Source
pub struct WorktreeManager { /* private fields */ }
Expand description

Manages git worktrees for coworker isolation

Implementations§

Source§

impl WorktreeManager

Source

pub fn from_current_dir() -> WorktreeResult<Self>

Create a new worktree manager by detecting the repository from the current directory.

Source

pub fn new(repo_root: PathBuf) -> WorktreeResult<Self>

Create a new worktree manager for a specific repository.

Source

pub fn worktree_path(&self, coworker_name: &str) -> PathBuf

Get the worktree path for a coworker

Source

pub fn create(&self, coworker_name: &str) -> WorktreeResult<PathBuf>

Create a worktree for a coworker.

Creates a new worktree at ~/.midtown/coworkers/<repo>/<name>/ detached at the current HEAD. The coworker should immediately create a feature branch for their task.

Source

pub fn remove(&self, coworker_name: &str, force: bool) -> WorktreeResult<()>

Remove a coworker’s worktree.

If force is true, removes the worktree even if it has uncommitted changes.

Source

pub fn prune(&self) -> WorktreeResult<()>

Prune stale worktree references.

Runs git worktree prune to clean up worktree administrative files for worktrees that no longer exist on disk.

Source

pub fn force_cleanup(&self, coworker_name: &str) -> WorktreeResult<()>

Force remove a worktree directory and prune git references.

This is useful for cleaning up stale worktrees that weren’t properly removed (e.g., after a crash or forced shutdown).

Source

pub fn list(&self) -> WorktreeResult<Vec<WorktreeInfo>>

List all worktrees for this repository.

Source

pub fn repo_root(&self) -> &Path

Get the repository root path.

Source

pub fn repo_name(&self) -> &str

Get the repository name.

Source

pub fn has_commits_beyond_base(&self, coworker_name: &str) -> bool

Check if a coworker’s worktree branch has commits beyond the base (detached HEAD).

Returns true if the branch has unique commits that are not on the main branch. Returns false if the branch has no commits beyond the base, or if the worktree is in detached HEAD state with no branch.

Source

pub fn has_uncommitted_changes(&self, coworker_name: &str) -> bool

Check if a coworker’s worktree has uncommitted or staged changes.

Returns true if the working tree is dirty (has modifications, staged changes, or untracked files). This prevents data loss when cleaning up worktrees that have work-in-progress that hasn’t been committed yet.

Source

pub fn is_branch_pr_merged(&self, coworker_name: &str) -> bool

Check if a coworker’s branch has a merged PR on GitHub.

Uses gh pr list to check if the branch’s PR was merged (e.g. via squash-merge). This catches cases where has_commits_beyond_base returns a false positive because squash-merged commits have different SHAs than the branch commits.

Source

pub fn safe_cleanup(&self, coworker_name: &str) -> WorktreeResult<bool>

Safely clean up a coworker’s worktree and branch if it has no commits and no uncommitted changes, or if the branch’s PR has been merged.

Returns Ok(true) if the worktree was cleaned up. Returns Ok(false) if the worktree has commits or uncommitted changes and was left intact. Returns Err if the cleanup operation failed.

Source

pub fn find_orphaned_worktrees( &self, active_coworkers: &[String], ) -> Vec<String>

Find orphaned worktrees - worktrees that exist on disk but have no corresponding active coworker.

Returns a list of coworker names whose worktrees are orphaned.

Trait Implementations§

Source§

impl Debug for WorktreeManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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 = Infallible

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,