{"record":{"id":"4dddfdb7d92e4fd3","repo":"xai-org/grok-build","slug":"bare-git-repository","errorCode":null,"errorMessage":"bare git repository: {}","messagePattern":"bare git repository: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/session/git.rs","lineNumber":215,"sourceCode":"    /// The path is definitively not inside a git repository.\n    NotARepo,\n    /// libgit2 failed for a reason other than \"not found\" (e.g. permissions,\n    /// unsupported extensions, corrupt repo). The user may or may not be in a\n    /// git repo — we can't tell.\n    DiscoveryFailed(anyhow::Error),\n}\n/// Discover whether `path` is inside a git repository.\n///\n/// Returns [`GitDiscoveryResult::Found`] with the worktree root on success,\n/// [`GitDiscoveryResult::NotARepo`] when the path is definitively outside any\n/// repo, or [`GitDiscoveryResult::DiscoveryFailed`] when libgit2 errors for\n/// an unexpected reason (so callers can avoid false-positive \"not a repo\"\n/// decisions).\npub fn discover_git_root(path: &Path) -> GitDiscoveryResult {\n    match Repository::discover(path) {\n        Ok(repo) => match repo.workdir() {\n            Some(root) => GitDiscoveryResult::Found(root.to_path_buf()),\n            None => GitDiscoveryResult::DiscoveryFailed(anyhow::anyhow!(\n                \"bare git repository: {}\",\n                path.display()\n            )),\n        },\n        Err(e) => {\n            let is_not_found =\n                e.code() == git2::ErrorCode::NotFound && e.class() == git2::ErrorClass::Repository;\n            if is_not_found {\n                GitDiscoveryResult::NotARepo\n            } else {\n                GitDiscoveryResult::DiscoveryFailed(e.into())\n            }\n        }\n    }\n}\n#[allow(\n    dead_code,\n    reason = \"Phase 1 internal git helper; will be used by WorkspaceChannel git operations\"","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/session/git.rs#L197-L233","documentation":"discover_git_root wraps git2::Repository::discover and returns the working-directory root when found. If discovery succeeds but the repository is bare (no workdir), it produces this error because there is no working-tree root to return. It prevents callers from treating a bare repo as a valid project root.","triggerScenarios":"Calling discover_git_root on a path that resolves to a bare repository (e.g. repo.git directory) or a repo with core.bare=true, so Repository::discover succeeds but repo.workdir() returns None.","commonSituations":"Pointing the workspace at a server-side bare clone (e.g. /srv/git/project.git), cloning with --bare for CI, or a misconfigured GIT_DIR where the checkout directory was moved/deleted leaving only the bare store.","solutions":["Point the API at a non-bare clone that has a working directory","Run `git config --bool core.bare` on the repo; if true, re-clone normally or set bare=false and restore the worktree","Re-clone the repository: `git clone <url>` instead of using the bare copy","If you must handle bare repos, match on GitDiscoveryResult::DiscoveryFailed and skip/notify instead of treating it as a project root"],"exampleFix":"// before\nlet root = discover_git_root(Path::new(\"/srv/git/project.git\"))?; // bare -> error\n// after\nlet path = Path::new(\"/home/me/project\"); // non-bare clone with workdir\nlet root = match discover_git_root(path) {\n    GitDiscoveryResult::Found(p) => p,\n    GitDiscoveryResult::DiscoveryFailed(e) => return Err(e),\n};","handlingStrategy":"validation","validationCode":"fn is_bare(path: &Path) -> bool {\n    git2::Repository::open(path)\n        .map(|r| r.is_bare())\n        .unwrap_or(false)\n}\nif is_bare(path) { eprintln!(\"{} is a bare repository\", path.display()); return; }","typeGuard":"fn has_workdir(path: &Path) -> Option<std::path::PathBuf> {\n    git2::Repository::discover(path).ok()?.workdir().map(|p| p.to_path_buf())\n}","tryCatchPattern":"match discover_git_root(path) {\n    GitDiscoveryResult::Found(root) => root,\n    GitDiscoveryResult::DiscoveryFailed(e) if e.to_string().contains(\"bare git repository\") => {\n        // skip bare repos; don't treat as 'not a repo' false-positive\n        return Ok(None);\n    }\n    GitDiscoveryResult::DiscoveryFailed(e) => return Err(e),\n}","preventionTips":["Verify with `git rev-parse --is-inside-work-tree` before pointing the workspace at a path","Avoid using server-side/bare clones as working workspaces; keep a normal clone","Check `core.bare` config when provisioning CI checkouts"],"tags":["git","bare-repository","path"],"backgroundTag":"bare-git-repository","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}