pub struct WorktreeManager { /* private fields */ }Expand description
Manages git worktrees for coworker isolation
Implementations§
Source§impl WorktreeManager
impl WorktreeManager
Sourcepub fn from_current_dir() -> WorktreeResult<Self>
pub fn from_current_dir() -> WorktreeResult<Self>
Create a new worktree manager by detecting the repository from the current directory.
Sourcepub fn new(repo_root: PathBuf) -> WorktreeResult<Self>
pub fn new(repo_root: PathBuf) -> WorktreeResult<Self>
Create a new worktree manager for a specific repository.
Sourcepub fn worktree_path(&self, coworker_name: &str) -> PathBuf
pub fn worktree_path(&self, coworker_name: &str) -> PathBuf
Get the worktree path for a coworker
Sourcepub fn create(&self, coworker_name: &str) -> WorktreeResult<PathBuf>
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.
Sourcepub fn remove(&self, coworker_name: &str, force: bool) -> WorktreeResult<()>
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.
Sourcepub fn prune(&self) -> WorktreeResult<()>
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.
Sourcepub fn force_cleanup(&self, coworker_name: &str) -> WorktreeResult<()>
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).
Sourcepub fn list(&self) -> WorktreeResult<Vec<WorktreeInfo>>
pub fn list(&self) -> WorktreeResult<Vec<WorktreeInfo>>
List all worktrees for this repository.
Sourcepub fn has_commits_beyond_base(&self, coworker_name: &str) -> bool
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.
Sourcepub fn has_uncommitted_changes(&self, coworker_name: &str) -> bool
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.
Sourcepub fn is_branch_pr_merged(&self, coworker_name: &str) -> bool
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.
Sourcepub fn safe_cleanup(&self, coworker_name: &str) -> WorktreeResult<bool>
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.
Sourcepub fn find_orphaned_worktrees(
&self,
active_coworkers: &[String],
) -> Vec<String>
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.