xai-org/grok-build · error
path '{}' is not within git repository '{}'
Error message
path '{}' is not within git repository '{}' What it means
This error comes from the path-normalization step of the read-files helper. Each absolute path is stripped of the git working-directory prefix; `Path::strip_prefix` fails when the path is not under that root, and the code converts that failure into this anyhow error naming both the offending path and the repo root.
Source
Thrown at crates/codegen/xai-grok-workspace/src/session/git.rs:1544
) -> 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)
}
})
.collect::<Result<Vec<_>, _>>()?;
let mut files = Vec::new();
let mut errors = Vec::new();
for path in &paths {
match read_version_content(&repo, path, &version) {
Ok((content, is_binary)) => {
files.push(GitReadFile {
path: path.clone(),
version: version.clone(),View on GitHub (pinned to bc7f02eddd)
Solutions
- Pass paths that are inside the repository working tree
- Use repo-relative paths instead of absolute ones
- Canonicalize (resolve symlinks) the path before calling so it matches git_root
- Verify with `path.strip_prefix(git_root).is_ok()` before invoking
Example fix
// before read_files(&cwd, &["/etc/hosts".into()]) // after read_files(&cwd, &["src/main.rs".into()])
Defensive patterns
Strategy: validation
Validate before calling
fn ensure_in_repo(p: &Path, git_root: &Path) -> Result<(), String> {
let canonical = p.canonicalize().map_err(|e| e.to_string())?;
if canonical.strip_prefix(git_root).is_ok() { Ok(()) } else { Err(format!("{} not under {}", p.display(), git_root.display())) }
} Prevention
- Prefer repo-relative paths in API calls
- Canonicalize paths (resolve symlinks) before passing them
- Never pass host/temp/config paths that live outside the repo
When it happens
Trigger: Passing an absolute path that lives outside the discovered repository root (different mount, sibling directory, symlinked path that doesn't resolve under git_root, or a path under a bare repo root from error 560's flow).
Common situations: Editor or agent passing temp files or config files outside the repo; hardcoded absolute paths from another machine/container; symlinked worktrees where the symlink path differs from `repo.workdir()`'s canonical path.
Related errors
- no .git file or directory found at {}
- git status failed: {}
- local workspace cwd must exist and be canonicalizable: {}: {
- local workspace cwd must be an existing directory: {}
- {LOCAL_WORKSPACE_HOME_DENIED}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/dc6d511c3d5ddebd.
Report an issue: GitHub.