{"record":{"id":"17be4c8608b1ea54","repo":"xai-org/grok-build","slug":"cannot-get-diffs-from-bare-repository","errorCode":null,"errorMessage":"cannot get diffs from bare repository","messagePattern":"cannot get diffs from bare repository","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/session/git.rs","lineNumber":1659,"sourceCode":"async fn diffs_ungated(\n    git_root: &Path,\n    paths: Option<&[String]>,\n    from: &str,\n    to: &str,\n    include_patch: bool,\n    include_content: bool,\n    merge_base: bool,\n) -> Result<GitDiffsData> {\n    let start = std::time::Instant::now();\n    let cwd = git_root.to_path_buf();\n    let paths = paths.map(|p| p.to_vec());\n    let from = from.to_string();\n    let to = to.to_string();\n    let result = tokio::task::spawn_blocking(move || {\n        let repo = Repository::discover(&cwd)?;\n        let work_dir = repo\n            .workdir()\n            .ok_or_else(|| anyhow::anyhow!(\"cannot get diffs from bare repository\"))?;\n        let effective_from = if merge_base {\n            match compute_merge_base(&repo, &from, &to) {\n                Some(oid) => oid.to_string(),\n                None => {\n                    tracing::warn!(\n                        from = %from,\n                        to = %to,\n                        \"git.diffs: could not compute merge-base, falling back to direct diff\"\n                    );\n                    from.clone()\n                }\n            }\n        } else {\n            from.clone()\n        };\n        let paths = match paths {\n            Some(ps) => Some(\n                ps.into_iter()","sourceCodeStart":1641,"sourceCodeEnd":1677,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/session/git.rs#L1641-L1677","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use a non-bare clone as `cwd` for diff operations","Clone normally (or `git clone --no-checkout` if space matters) before diffing","Use plumbing (`git diff-tree`) against the bare repo if diffs without a worktree are acceptable","Check `git rev-parse --is-bare-repository` first"],"exampleFix":"// before\ndiffs(\"/srv/project.git\", \"main\", \"feature\")\n// after\ndiffs(\"/srv/project\", \"main\", \"feature\")","handlingStrategy":"validation","validationCode":"let out = std::process::Command::new(\"git\").args([\"rev-parse\",\"--is-bare-repository\"]).current_dir(&cwd).output()?;\nif String::from_utf8_lossy(&out.stdout).trim() == \"true\" {\n    return Err(\"cannot diff in a bare repository; clone non-bare\".into());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use non-bare checkouts for diff workflows","Check bare-ness before invoking diff APIs","Avoid server-side storage directories as cwd"],"tags":["git","bare-repository","diff"],"backgroundTag":"bare-repository-no-worktree","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}