Skip to main content

Module worktree

Module worktree 

Source
Expand description

Git worktree management for parallel Ralph loops.

Provides filesystem isolation for concurrent loops using git worktrees. Each parallel loop gets its own working directory with full filesystem isolation, sharing only .git history. Conflicts are resolved at merge time.

§Example

use ralph_core::worktree::{Worktree, WorktreeConfig, create_worktree, remove_worktree, list_worktrees};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = WorktreeConfig::default();

    // Create worktree for a parallel loop
    let worktree = create_worktree(".", "ralph-20250124-a3f2", &config)?;
    println!("Created worktree at: {}", worktree.path.display());

    // List all worktrees
    let worktrees = list_worktrees(".")?;
    for wt in worktrees {
        println!("  {}: {}", wt.branch, wt.path.display());
    }

    // Clean up when done
    remove_worktree(".", &worktree.path)?;
    Ok(())
}

Structs§

SyncStats
Statistics about files synced to a worktree.
Worktree
Information about a git worktree.
WorktreeConfig
Configuration for worktree operations.

Enums§

WorktreeError
Errors that can occur during worktree operations.

Functions§

create_worktree
Create a new worktree for a parallel Ralph loop.
ensure_gitignore
Ensure the worktree directory is in .gitignore.
list_ralph_worktrees
Get the list of Ralph-specific worktrees (those with ralph/ branches).
list_worktrees
List all git worktrees in the repository.
remove_worktree
Remove a worktree and optionally its branch.
sync_working_directory_to_worktree
Sync untracked and unstaged files from the main repo to a worktree.
worktree_exists
Check if a worktree exists for the given loop ID.