Skip to main content

detect_worktree

Function detect_worktree 

Source
pub fn detect_worktree(cwd: &Path) -> Result<Option<WorktreeInfo>, Error>
Expand description

Detect if the given directory is within a git worktree.

Uses the provided cwd path to determine which worktree (if any) the directory belongs to. This avoids relying on process-global std::env::current_dir() which is unsafe in multi-threaded tests.

Returns:

  • Ok(None) if not in a git repo or in the main worktree
  • Ok(Some(WorktreeInfo)) if in a secondary worktree
  • Err if there’s an error running git commands