Skip to main content

WorktreeManager

Struct WorktreeManager 

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

Manages git worktrees for polecat sessions.

Each polecat session runs in an isolated git worktree to enable parallel work without conflicts. The manager handles creation, tracking, and cleanup of these worktrees.

Implementations§

Source§

impl WorktreeManager

Source

pub fn new( repo_root: impl Into<PathBuf>, worktree_root: impl AsRef<str>, max_polecats: u32, ) -> Self

Create a new WorktreeManager.

§Arguments
  • repo_root - Path to the repository root.
  • worktree_root - Relative path for worktrees (e.g., .grite/worktrees).
  • max_polecats - Maximum number of concurrent polecat worktrees.
Source

pub fn worktree_root(&self) -> &Path

Get the worktree root path.

Source

pub fn create(&self, session_id: &str) -> Result<PathBuf, WorktreeError>

Create a new worktree for a session.

The worktree is named after the session ID and created with a detached HEAD at the current commit.

§Arguments
  • session_id - Session ID (e.g., s-20250117-a2f9).
§Returns

The absolute path to the created worktree.

Source

pub fn list(&self) -> Result<Vec<WorktreeInfo>, WorktreeError>

List all managed worktrees.

Returns worktrees in the worktree_root directory, excluding the main worktree.

Source

pub fn get(&self, session_id: &str) -> Result<WorktreeInfo, WorktreeError>

Get a worktree by session ID.

Source

pub fn remove(&self, session_id: &str) -> Result<(), WorktreeError>

Remove a worktree by session ID.

Uses --force to remove even if the worktree has uncommitted changes.

Source

pub fn prune(&self) -> Result<(), WorktreeError>

Prune stale worktree administrative files.

Source

pub fn cleanup_stale( &self, active_session_ids: &HashSet<String>, ) -> Result<CleanupReport, WorktreeError>

Clean up worktrees for sessions that are no longer active.

§Arguments
  • active_session_ids - Set of session IDs that are still active.
§Returns

A report of cleaned up worktrees and any errors.

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.