xai-org/grok-build · error
cannot stage content in bare repository
Error message
cannot stage content in bare repository
What it means
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.
Source
Thrown at crates/codegen/xai-grok-workspace/src/session/git.rs:3373
} else {
PushStatus::Failed
}
};
Ok(GitPushResult {
status,
output: scrub_git_output(&out),
})
}
pub async fn stage_content(git_root: &Path, path: &str, content: &str) -> Result<()> {
let git_root_buf = git_root.to_path_buf();
let path = path.to_string();
let content = content.to_string();
tokio::task::spawn_blocking(move || -> Result<()> {
let git_root = git_root_buf;
let repo = Repository::open(&git_root)?;
let work_dir = repo
.workdir()
.ok_or_else(|| anyhow::anyhow!("cannot stage content in bare repository"))?;
let relative_path = if Path::new(&path).is_absolute() {
Path::new(&path)
.strip_prefix(work_dir)
.map_err(|_| {
anyhow::anyhow!(
"path '{}' is not within git repository '{}'",
path,
work_dir.display()
)
})?
.to_string_lossy()
.to_string()
} else {
path.clone()
};
let blob_oid = repo.blob(content.as_bytes())?;
let mut index = repo.index()?;
let existing_mode = indexView on GitHub (pinned to bc7f02eddd)
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.
Example fix
// before
let root = PathBuf::from("/srv/repos/project.git"); // bare
stage_content(&root, "src/main.rs", "...").await?;
// after
let root = PathBuf::from("/srv/worktrees/project"); // non-bare checkout
debug_assert_eq!(run_git(&root, &["rev-parse", "--is-bare-repository"]), "false");
stage_content(&root, "src/main.rs", "...").await?; Defensive patterns
Strategy: validation
Validate before calling
let out = Command::new("git").args(["rev-parse", "--is-bare-repository"]).current_dir(&root).output()?;
if String::from_utf8_lossy(&out.stdout).trim() == "true" {
return Err(format!("{} is a bare repository; use the working copy", root.display()));
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- bare repository has no working directory
- bare git repository: {}
- cannot read working files from bare repository
- cannot read files from bare repository
- cannot get diffs from bare repository
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/e613361740d1f101.
Report an issue: GitHub.