pub struct WorktreeManager { /* private fields */ }Expand description
Manages git worktrees for a project.
Implementations§
Source§impl WorktreeManager
impl WorktreeManager
Sourcepub fn new(project_dir: impl Into<PathBuf>) -> Self
pub fn new(project_dir: impl Into<PathBuf>) -> Self
Create a new manager for the given project directory.
Worktrees are stored under ~/.opendev/data/worktree/.
Sourcepub fn with_base(
project_dir: impl Into<PathBuf>,
worktree_base: impl Into<PathBuf>,
) -> Self
pub fn with_base( project_dir: impl Into<PathBuf>, worktree_base: impl Into<PathBuf>, ) -> Self
Create a new manager with a custom worktree base directory.
Primarily useful for tests.
Sourcepub fn project_dir(&self) -> &Path
pub fn project_dir(&self) -> &Path
Get the project directory.
Sourcepub fn worktree_base(&self) -> &Path
pub fn worktree_base(&self) -> &Path
Get the worktree base directory.
Sourcepub async fn create(
&mut self,
name: Option<&str>,
branch: Option<&str>,
base_branch: &str,
) -> Result<WorktreeInfo, WorktreeError>
pub async fn create( &mut self, name: Option<&str>, branch: Option<&str>, base_branch: &str, ) -> Result<WorktreeInfo, WorktreeError>
Create a new worktree.
name: worktree name (auto-generated ifNone)branch: branch name (defaults toworktree-{name})base_branch: base commit/branch to start from (defaults to"HEAD")
Sourcepub async fn list(&self) -> Result<Vec<WorktreeInfo>, WorktreeError>
pub async fn list(&self) -> Result<Vec<WorktreeInfo>, WorktreeError>
List all worktrees for the project (from git worktree list --porcelain).
Sourcepub async fn remove(
&mut self,
name: &str,
force: bool,
) -> Result<(), WorktreeError>
pub async fn remove( &mut self, name: &str, force: bool, ) -> Result<(), WorktreeError>
Remove a worktree by name (or absolute path).
Sourcepub async fn cleanup(&self) -> Result<String, WorktreeError>
pub async fn cleanup(&self) -> Result<String, WorktreeError>
Clean up stale/prunable worktree references.
Sourcepub fn tracked(&self) -> &HashMap<String, WorktreeInfo>
pub fn tracked(&self) -> &HashMap<String, WorktreeInfo>
Get tracked worktrees in session state.
Sourcepub fn track(&mut self, name: String, info: WorktreeInfo)
pub fn track(&mut self, name: String, info: WorktreeInfo)
Track a worktree in session state.
Sourcepub fn untrack(&mut self, name: &str) -> Option<WorktreeInfo>
pub fn untrack(&mut self, name: &str) -> Option<WorktreeInfo>
Untrack a worktree from session state.
Auto 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
Mutably borrows from an owned value. Read more