nikivdev/code · error

derived shared repo root {} does not contain .git

Error message

derived shared repo root {} does not contain .git

What it means

After deriving a shared repo root from the jj repo directory, the code sanity-checks that the derived root actually contains a `.git` entry. If it does not, the derivation is wrong (or the workspace is not git-colocated) and this error names the bad root path.

Source

Thrown at src/pr_preview.rs:1425

    .canonicalize()
    .with_context(|| {
        format!(
            "failed to resolve JJ repo pointer for {}",
            workspace_root.display()
        )
    })?;
    let repo_root = jj_repo_dir
        .parent()
        .and_then(Path::parent)
        .map(Path::to_path_buf)
        .ok_or_else(|| {
            anyhow::anyhow!(
                "failed to derive shared repo root from {}",
                jj_repo_dir.display()
            )
        })?;
    if !repo_root.join(".git").exists() {
        bail!(
            "derived shared repo root {} does not contain .git",
            repo_root.display()
        );
    }
    Ok(repo_root)
}

fn detect_jj_head_ref(workspace_root: &Path) -> Result<String> {
    let output = Command::new("jj")
        .current_dir(workspace_root)
        .args(["log", "-r", "@ | @-", "--no-graph", "-T", "bookmarks"])
        .output()
        .with_context(|| format!("failed to run jj log in {}", workspace_root.display()))?;
    if !output.status.success() {
        bail!("jj log failed in {}", workspace_root.display());
    }
    let mut bookmarks = parse_jj_bookmark_tokens(&String::from_utf8_lossy(&output.stdout));
    bookmarks.sort();

View on GitHub (pinned to a747e741ae)

Solutions

  1. Ensure the repo is git-colocated (`jj git init --colocate`) or verify `.git` exists at the expected root
  2. Check that `.jj/repo` points to the correct store for this workspace
  3. Operate directly on the git work tree instead of via the jj workspace
Defensive patterns

Strategy: validation

Validate before calling

let root = resolve_repo_root_from_jj_workspace(ws)?;
if !root.join(".git").exists() {
    anyhow::bail!("{} is not git-colocated", root.display());
}

Type guard

fn is_git_colocated(root: &Path) -> bool {
    root.join(".git").exists()
}

Try / catch

if let Err(e) = run_pr_preview(cmd) {
    if e.to_string().contains("does not contain .git") {
        eprintln!("Use a git-colocated jj workspace or the git work tree");
    }
}

Prevention

When it happens

Trigger: resolve_repo_root_from_jj_workspace derives a root whose `.git` check fails — e.g. a non-colocated jj repo, or the `.jj/repo` pointer resolving to an unexpected location.

Common situations: jj workspaces created without git colocation; custom or relocated jj repo stores; version changes in jj's layout altering how the root should be derived.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/0ac1a31249060a7c. Report an issue: GitHub.