{"record":{"id":"3412ce25d0f7ae50","repo":"xai-org/grok-build","slug":"cannot-read-working-files-from-bare-repository","errorCode":null,"errorMessage":"cannot read working files from bare repository","messagePattern":"cannot read working files from bare repository","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/session/git.rs","lineNumber":759,"sourceCode":") -> Option<git2::Diff<'a>> {\n    if base.is_working_state() || head.is_working_state() {\n        diff_working_state(repo, base, head, opts)\n    } else {\n        let GitRef::Treeish(base_ref) = base else {\n            return None;\n        };\n        let GitRef::Treeish(head_ref) = head else {\n            return None;\n        };\n        diff_compare(repo, base_ref, head_ref, merge_base, opts)\n    }\n}\nfn read_version_bytes(repo: &Repository, path: &str, version: &str) -> Result<Vec<u8>> {\n    match GitRef::parse(version) {\n        GitRef::Workdir => {\n            let full_path = repo\n                .workdir()\n                .ok_or_else(|| anyhow::anyhow!(\"cannot read working files from bare repository\"))?\n                .join(path);\n            std::fs::read(&full_path)\n                .map_err(|e| anyhow::anyhow!(\"failed to read '{}': {}\", path, e))\n        }\n        GitRef::Index => read_blob_from_index(repo, path),\n        GitRef::Treeish(refspec) => {\n            let obj = repo\n                .revparse_single(&refspec)\n                .map_err(|e| anyhow::anyhow!(\"'{}' is not a valid revision: {}\", refspec, e))?;\n            let commit = obj\n                .peel_to_commit()\n                .map_err(|e| anyhow::anyhow!(\"'{}' does not refer to a commit: {}\", refspec, e))?;\n            let tree = commit.tree()?;\n            read_blob_from_tree(repo, &tree, path)\n        }\n    }\n}\n/// Binary files return empty content with is_binary=true.","sourceCodeStart":741,"sourceCodeEnd":777,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/session/git.rs#L741-L777","documentation":"read_version_bytes serves GitRef::Workdir by joining the repo workdir with the relative path and reading from disk. Bare repositories have no working directory, so repo.workdir() is None and this error is thrown instead of attempting a filesystem read that cannot succeed.","triggerScenarios":"Calling read_version_content with version 'workdir' (or the default workdir variant) on a repository discovered as bare — e.g. after discover_git_root flagged a bare repo but the read was still attempted.","commonSituations":"Workspace pointed at a bare server-side clone, a --bare CI checkout, or session metadata persisting a path that later became bare; also GIT_DIR tricks that hide the worktree.","solutions":["Use a non-bare clone with a working tree for session content reads","Read a committed version instead: use GitRef::Treeish (e.g. HEAD) or GitRef::Index","If bare operation is required, materialize content via `git show HEAD:<path>` equivalent (tree/blob reads)","Match on this error and return a clear 'no working files available' result to the caller"],"exampleFix":"// before\nlet bytes = read_version_bytes(&repo, \"src/main.rs\", \"workdir\")?; // bare repo\n// after\nlet bytes = match read_version_bytes(&repo, \"src/main.rs\", \"workdir\") {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"bare repository\") => {\n        read_version_bytes(&repo, \"src/main.rs\", \"HEAD\")? // fall back to committed version\n    }\n    Err(e) => return Err(e),\n};","handlingStrategy":"fallback","validationCode":"fn workdir_readable(repo: &git2::Repository) -> Option<std::path::PathBuf> {\n    if repo.is_bare() { None } else { repo.workdir().map(|p| p.to_path_buf()) }\n}","typeGuard":"fn is_bare(repo: &git2::Repository) -> bool { repo.is_bare() }","tryCatchPattern":"match read_version_bytes(repo, path, \"workdir\") {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"bare repository\") => {\n        read_version_bytes(repo, path, \"HEAD\")? // committed content instead\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check repo.is_bare() before requesting workdir versions","Use bare repos only for storage; keep a non-bare clone for session work","For bare repos, request treeish/index versions instead of workdir"],"tags":["git","bare-repository","workdir"],"backgroundTag":"bare-git-repository","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}