Hmbown/CodeWhale · error · anyhow::Error
repo root does not exist: {}
Error message
repo root does not exist: {} What it means
Thrown by provision_worktree() in codewhale-lane before any git command runs: the WorktreeProvision.repo_root path passed by the caller does not exist on disk. The check guards the later `git -C <repo_root> worktree add`, which would otherwise fail with a less actionable error. It is a pure caller-input validation error, not a git state problem.
Source
Thrown at crates/lane/src/worktree.rs:36
/// Directory for the new worktree (created by `git worktree add`).
pub path: PathBuf,
/// Base ref to branch from (default `HEAD`).
pub base_ref: Option<String>,
}
#[derive(Debug, Clone)]
pub struct ProvisionedWorktree {
pub path: PathBuf,
pub branch: String,
}
/// Create a git worktree + branch for a lane.
pub fn provision_worktree(spec: &WorktreeProvision) -> Result<ProvisionedWorktree> {
if spec.branch.trim().is_empty() {
bail!("worktree branch must not be empty");
}
if !spec.repo_root.exists() {
bail!("repo root does not exist: {}", spec.repo_root.display());
}
if let Some(parent) = spec.path.parent() {
fs::create_dir_all(parent)
.with_context(|| format!("create worktree parent {}", parent.display()))?;
}
let base = spec.base_ref.as_deref().unwrap_or("HEAD");
// Capture git output instead of inheriting the caller's terminal. Runtime
// callers include the raw-mode TUI launch screen, where even one inherited
// progress/error line corrupts the alternate-screen buffer.
let output = Command::new("git")
.current_dir(&spec.repo_root)
.args([
"worktree",
"add",
"-b",
&spec.branch,
&spec.path.to_string_lossy(),
base,View on GitHub (pinned to 0c42157ee5)
Solutions
- Verify the path exists and is a git repository before calling: path.is_dir() && path.join(".git").exists()
- Derive repo_root from git itself (`git rev-parse --show-toplevel`) instead of trusting configuration
- Canonicalize the path (std::fs::canonicalize) so later comparisons and git invocations use one absolute form
- If the repo legitimately moved, update the lane/worktree spec source (config or state store) to the new location
Example fix
// before
let spec = WorktreeProvision {
repo_root: PathBuf::from(&config.repo_path),
branch: branch_name.clone(),
path: worktree_dir.clone(),
base_ref: None,
};
let wt = provision_worktree(&spec)?;
// after
let repo_root = std::fs::canonicalize(&config.repo_path)
.with_context(|| format!("locate repo at {}", config.repo_path))?;
if !repo_root.join(".git").exists() {
bail!("{} is not a git repository", repo_root.display());
}
let spec = WorktreeProvision {
repo_root,
branch: branch_name.clone(),
path: worktree_dir.clone(),
base_ref: None,
};
let wt = provision_worktree(&spec)?; Defensive patterns
Strategy: validation
Validate before calling
fn usable_repo_root(p: &Path) -> bool {
p.is_dir() && p.join(".git").exists()
}
// before provisioning:
if !usable_repo_root(&spec.repo_root) {
bail!("repo root {} missing or not a git repo", spec.repo_root.display());
} Prevention
- Derive repo_root via `git rev-parse --show-toplevel` instead of storing absolute paths in config
- Canonicalize the path once at discovery and pass the same absolute PathBuf everywhere
- Fail fast in lane-spec loading when the referenced repo does not resolve
When it happens
Trigger: Calling provision_worktree() with a repo_root that is a typo'd path, a relative path resolved against an unexpected current working directory, a repo directory that was moved/deleted after discovery, or a repo that was never cloned. Also triggered when repo_root is derived from stale configuration or an env var that is unset (yielding an empty or wrong path).
Common situations: CI sandboxes where the checkout lives at a different absolute path than locally; configs persisting an old workspace location; relative paths like "../repo" interpreted from the TUI's cwd instead of the launcher's; lane specs replayed after the user reorganized their workspace.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- worktree branch must not be empty
- git worktree add failed for branch {} at {}{}{}
- --worktree-repo and --branch must be provided together
- Runtime store root cannot contain '..' components
- invalid on-disk package directory for skill '{}'
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/ecba070531e1f65a.
Report an issue: GitHub.