{"record":{"id":"e613361740d1f101","repo":"xai-org/grok-build","slug":"cannot-stage-content-in-bare-repository","errorCode":null,"errorMessage":"cannot stage content in bare repository","messagePattern":"cannot stage content in bare repository","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/session/git.rs","lineNumber":3373,"sourceCode":"        } else {\n            PushStatus::Failed\n        }\n    };\n    Ok(GitPushResult {\n        status,\n        output: scrub_git_output(&out),\n    })\n}\npub async fn stage_content(git_root: &Path, path: &str, content: &str) -> Result<()> {\n    let git_root_buf = git_root.to_path_buf();\n    let path = path.to_string();\n    let content = content.to_string();\n    tokio::task::spawn_blocking(move || -> Result<()> {\n        let git_root = git_root_buf;\n        let repo = Repository::open(&git_root)?;\n        let work_dir = repo\n            .workdir()\n            .ok_or_else(|| anyhow::anyhow!(\"cannot stage content in bare repository\"))?;\n        let relative_path = if Path::new(&path).is_absolute() {\n            Path::new(&path)\n                .strip_prefix(work_dir)\n                .map_err(|_| {\n                    anyhow::anyhow!(\n                        \"path '{}' is not within git repository '{}'\",\n                        path,\n                        work_dir.display()\n                    )\n                })?\n                .to_string_lossy()\n                .to_string()\n        } else {\n            path.clone()\n        };\n        let blob_oid = repo.blob(content.as_bytes())?;\n        let mut index = repo.index()?;\n        let existing_mode = index","sourceCodeStart":3355,"sourceCodeEnd":3391,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/session/git.rs#L3355-L3391","documentation":"Staging content requires a working directory: the library opens the repository with git2 and calls repo.workdir(), which returns None for bare repositories. Without a worktree there is no on-disk tree in which to create the file, so the library throws this error instead of staging anything.","triggerScenarios":"Calling the stage-content API (crates/codegen/xai-grok-workspace/src/session/git.rs:3373) with git_root pointing at a bare repository (e.g. a `repo.git` directory, or GIT_DIR checked out without a worktree).","commonSituations":"A misconfigured workspace root pointing at the server-side bare clone instead of the checked-out working copy; using the .git directory itself as the root; pointing at a remote URL cloned with --bare during setup.","solutions":["Point the operation at the non-bare working copy (the directory containing .git), not the bare repo.","If you only have a bare repo, create a worktree (git worktree add) or a normal clone and use that path.","Verify the target with `git rev-parse --is-bare-repository` during configuration and fail fast with a clear setup error."],"exampleFix":"// before\nlet root = PathBuf::from(\"/srv/repos/project.git\"); // bare\nstage_content(&root, \"src/main.rs\", \"...\").await?;\n// after\nlet root = PathBuf::from(\"/srv/worktrees/project\"); // non-bare checkout\ndebug_assert_eq!(run_git(&root, &[\"rev-parse\", \"--is-bare-repository\"]), \"false\");\nstage_content(&root, \"src/main.rs\", \"...\").await?;","handlingStrategy":"validation","validationCode":"let out = Command::new(\"git\").args([\"rev-parse\", \"--is-bare-repository\"]).current_dir(&root).output()?;\nif String::from_utf8_lossy(&out.stdout).trim() == \"true\" {\n    return Err(format!(\"{} is a bare repository; use the working copy\", root.display()));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure the workspace root to the checked-out working copy, never the bare repo or its .git dir.","Validate the root at startup with git rev-parse --is-bare-repository.","Document the distinction for operators deploying server-side bare clones."],"tags":["git","bare-repository","configuration"],"backgroundTag":"bare-repository-no-workdir","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}