xai-org/grok-build · error

cannot get diffs from bare repository

Error message

cannot get diffs from bare repository

What it means

Thrown by the diff helper in the git module. It discovers the repository for `cwd`, then requires `repo.workdir()`; for a bare repository there is no working directory, so computing diffs of working-tree files is impossible and this error is returned.

Source

Thrown at crates/codegen/xai-grok-workspace/src/session/git.rs:1659

async fn diffs_ungated(
    git_root: &Path,
    paths: Option<&[String]>,
    from: &str,
    to: &str,
    include_patch: bool,
    include_content: bool,
    merge_base: bool,
) -> Result<GitDiffsData> {
    let start = std::time::Instant::now();
    let cwd = git_root.to_path_buf();
    let paths = paths.map(|p| p.to_vec());
    let from = from.to_string();
    let to = to.to_string();
    let result = tokio::task::spawn_blocking(move || {
        let repo = Repository::discover(&cwd)?;
        let work_dir = repo
            .workdir()
            .ok_or_else(|| anyhow::anyhow!("cannot get diffs from bare repository"))?;
        let effective_from = if merge_base {
            match compute_merge_base(&repo, &from, &to) {
                Some(oid) => oid.to_string(),
                None => {
                    tracing::warn!(
                        from = %from,
                        to = %to,
                        "git.diffs: could not compute merge-base, falling back to direct diff"
                    );
                    from.clone()
                }
            }
        } else {
            from.clone()
        };
        let paths = match paths {
            Some(ps) => Some(
                ps.into_iter()

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Use a non-bare clone as `cwd` for diff operations
  2. Clone normally (or `git clone --no-checkout` if space matters) before diffing
  3. Use plumbing (`git diff-tree`) against the bare repo if diffs without a worktree are acceptable
  4. Check `git rev-parse --is-bare-repository` first

Example fix

// before
diffs("/srv/project.git", "main", "feature")
// after
diffs("/srv/project", "main", "feature")
Defensive patterns

Strategy: validation

Validate before calling

let out = std::process::Command::new("git").args(["rev-parse","--is-bare-repository"]).current_dir(&cwd).output()?;
if String::from_utf8_lossy(&out.stdout).trim() == "true" {
    return Err("cannot diff in a bare repository; clone non-bare".into());
}

Prevention

When it happens

Trigger: Calling the diff API with `cwd` inside a bare repository (e.g. `repo.git`, `--bare` clone, or server-side mirror) such that `Repository::discover` resolves to the bare repo.

Common situations: Running diff tooling on a git server's storage directory; CI jobs that clone with `--bare` or `--mirror` and then try to diff files; `GIT_DIR` misconfiguration.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/17be4c8608b1ea54. Report an issue: GitHub.