xai-org/grok-build · error
cannot read files from bare repository
Error message
cannot read files from bare repository
What it means
This error is thrown by a file-reading helper in the workspace git module. After `Repository::discover` opens the repo containing `cwd`, the code calls `repo.workdir()` and errors if it returns None, which happens only when the discovered repository is bare (has no working tree). Since the function's purpose is to map absolute file paths into repo-relative paths under the working directory, a bare repo cannot satisfy the operation.
Source
Thrown at crates/codegen/xai-grok-workspace/src/session/git.rs:1535
cli_err.context(format!(
"CLI fallback also failed (libgit2 error: {libgit2_err})"
))
})
}
pub async fn read_files(
git_root: &Path,
paths: &[String],
version: &str,
) -> Result<GitReadFilesData> {
let start = std::time::Instant::now();
let cwd = git_root.to_path_buf();
let paths = paths.to_vec();
let version = version.to_string();
let result = tokio::task::spawn_blocking(move || {
let repo = Repository::discover(&cwd)?;
let git_root = repo
.workdir()
.ok_or_else(|| anyhow::anyhow!("cannot read files from bare repository"))?;
let paths: Vec<String> = paths
.into_iter()
.map(|p| {
if Path::new(&p).is_absolute() {
Path::new(&p)
.strip_prefix(git_root)
.map(|rel| rel.to_string_lossy().to_string())
.map_err(|_| {
anyhow::anyhow!(
"path '{}' is not within git repository '{}'",
p,
git_root.display()
)
})
} else {
Ok(p)
}
})View on GitHub (pinned to bc7f02eddd)
Solutions
- Run the API with `cwd` set inside a non-bare checkout of the repository
- Clone the repository normally (without --bare) and use that directory
- If you must read from a bare repo, use plumbing commands (e.g. `git show HEAD:path`) instead of working-tree file reads
- Check `git rev-parse --is-bare-repository` in the target directory before calling
Example fix
// before
let cwd = Path::new("/srv/repo.git"); // bare
// after
let cwd = Path::new("/srv/repo-checkout"); // non-bare clone Defensive patterns
Strategy: validation
Validate before calling
let out = std::process::Command::new("git").args(["rev-parse","--is-bare-repository"]).current_dir(&cwd).output()?;
if String::from_utf8_lossy(&out.stdout).trim() == "true" {
return Err("cwd is a bare repository; use a non-bare checkout".into());
} Prevention
- Always point tooling at a normal (non-bare) clone
- Verify `git rev-parse --is-bare-repository` returns false before file operations
- Avoid --bare/--mirror clones for workflows that read working-tree files
When it happens
Trigger: Calling the read-files API with `cwd` inside (or pointing at) a bare repository, e.g. a `repo.git` server-side clone, a `--bare` clone, or a directory whose discover walk reaches a bare repo before a non-bare one.
Common situations: Pointing tooling at a server-side bare clone on a remote host; cloning with `git clone --bare` for CI artifact reads; `GIT_DIR` env pointing at a bare repo so discover resolves to it instead of the intended worktree.
Related errors
- no .git file or directory found at {}
- git status failed: {}
- bare repository has no working directory
- worktree creation task failed: {e}
- bare git repository: {}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/d9a8e3ac3e8818d8.
Report an issue: GitHub.