pub struct WorktreeManager { /* private fields */ }Expand description
Manages git worktree operations for a repository.
All commands are run via the git CLI in async subprocesses.
Implementations§
Source§impl WorktreeManager
impl WorktreeManager
Sourcepub fn new(repo_root: &Path) -> Result<Self>
pub fn new(repo_root: &Path) -> Result<Self>
Create a manager for the repository at repo_root.
Verifies that the directory is inside a git repository.
Sourcepub fn for_current_repo() -> Result<Self>
pub fn for_current_repo() -> Result<Self>
Create a manager by auto-detecting the git repo from the current directory (or any directory).
Sourcepub async fn create(&self, opts: &WorktreeCreateOpts) -> Result<WorktreeInfo>
pub async fn create(&self, opts: &WorktreeCreateOpts) -> Result<WorktreeInfo>
Create a new worktree with the given options.
Sourcepub async fn create_worktree(
&self,
branch: &str,
target_path: &Path,
start_point: Option<&str>,
) -> Result<WorktreeInfo>
pub async fn create_worktree( &self, branch: &str, target_path: &Path, start_point: Option<&str>, ) -> Result<WorktreeInfo>
Create a worktree at target_path that checks out branch.
If branch doesn’t exist yet, it is created from start_point (or HEAD).
Sourcepub async fn list(&self) -> Result<WorktreeList>
pub async fn list(&self) -> Result<WorktreeList>
List all worktrees in the repository.
Uses git worktree list --porcelain for machine-readable output.
Sourcepub async fn remove(&self, path: &Path, force: bool) -> Result<()>
pub async fn remove(&self, path: &Path, force: bool) -> Result<()>
Remove a worktree by its path.
Fails if the worktree has uncommitted changes unless force is true.
Sourcepub async fn remove_by_branch(&self, branch: &str, force: bool) -> Result<()>
pub async fn remove_by_branch(&self, branch: &str, force: bool) -> Result<()>
Remove a worktree by branch name.
Finds the worktree with the given branch and removes it.
Sourcepub async fn prune(&self) -> Result<()>
pub async fn prune(&self) -> Result<()>
Prune deleted worktrees (clean up stale administrative files).
Sourcepub async fn remove_and_delete_branch(
&self,
branch: &str,
force: bool,
) -> Result<()>
pub async fn remove_and_delete_branch( &self, branch: &str, force: bool, ) -> Result<()>
Remove a worktree and delete its branch.
Sourcepub async fn force_remove_and_delete_branch(&self, branch: &str) -> Result<()>
pub async fn force_remove_and_delete_branch(&self, branch: &str) -> Result<()>
Remove a worktree and force-delete its branch (even if unmerged).
Sourcepub async fn merge(
&self,
source_branch: &str,
target_branch: &str,
) -> Result<MergeResult>
pub async fn merge( &self, source_branch: &str, target_branch: &str, ) -> Result<MergeResult>
Merge a worktree’s branch into a target branch.
This checks out target_branch in the main worktree, merges
source_branch, and returns the result.
Sourcepub async fn merge_and_remove(
&self,
source_branch: &str,
target_branch: &str,
) -> Result<MergeResult>
pub async fn merge_and_remove( &self, source_branch: &str, target_branch: &str, ) -> Result<MergeResult>
Merge a worktree’s branch into target_branch, then remove the
worktree and delete the source branch.
On merge conflict, the worktree is NOT removed — the caller must
resolve conflicts and then call remove_and_delete_branch.
Sourcepub async fn branch(
&self,
branch: &str,
target_path: &Path,
start_point: Option<&str>,
) -> Result<WorktreeInfo>
pub async fn branch( &self, branch: &str, target_path: &Path, start_point: Option<&str>, ) -> Result<WorktreeInfo>
Create a new branch + worktree in one operation.
Equivalent to git worktree add -b <branch> <path> [<start-point>].
Sourcepub async fn feature(&self, branch: &str) -> Result<WorktreeInfo>
pub async fn feature(&self, branch: &str) -> Result<WorktreeInfo>
Create a feature worktree: sibling directory named after the branch.
Sourcepub async fn hotfix(
&self,
branch: &str,
start_point: &str,
) -> Result<WorktreeInfo>
pub async fn hotfix( &self, branch: &str, start_point: &str, ) -> Result<WorktreeInfo>
Create a hotfix worktree: branching off a specific start point.
Sourcepub async fn is_dirty(&self, worktree_path: &Path) -> Result<bool>
pub async fn is_dirty(&self, worktree_path: &Path) -> Result<bool>
Check whether a worktree has uncommitted changes.
Sourcepub async fn current_branch(&self, worktree_path: &Path) -> Result<String>
pub async fn current_branch(&self, worktree_path: &Path) -> Result<String>
Get the current branch name of a worktree.
Sourcepub async fn head_commit(&self, worktree_path: &Path) -> Result<String>
pub async fn head_commit(&self, worktree_path: &Path) -> Result<String>
Get the commit SHA of HEAD in a worktree.
Sourcepub async fn branch_exists(&self, branch: &str) -> Result<bool>
pub async fn branch_exists(&self, branch: &str) -> Result<bool>
Check if a branch name already exists in the repo.
Trait Implementations§
Source§impl Clone for WorktreeManager
impl Clone for WorktreeManager
Source§fn clone(&self) -> WorktreeManager
fn clone(&self) -> WorktreeManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for WorktreeManager
impl RefUnwindSafe for WorktreeManager
impl Send for WorktreeManager
impl Sync for WorktreeManager
impl Unpin for WorktreeManager
impl UnsafeUnpin for WorktreeManager
impl UnwindSafe for WorktreeManager
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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