xai-org/grok-build · error
git status failed: {}
Error message
git status failed: {} What it means
collect_source_dirty_state runs `git status --porcelain=v2 -z --untracked-files=all` in the source worktree to compute a dirty-state report. If git exits non-zero, the captured stderr is surfaced via anyhow::bail. The library treats an unparseable/failed git status as fatal because the dirty-file list cannot be trusted.
Source
Thrown at crates/codegen/xai-fast-worktree/src/sync.rs:71
}
}
/// Collect dirty state from a source repository.
///
/// Runs `git status --porcelain=v2 -z --untracked-files=all` on the source
/// and captures the output. The result can be shared across multiple
/// [`WorktreeSync::sync_from_precomputed`] calls.
///
/// This is a **blocking** function — call from `spawn_blocking` in async contexts.
pub fn collect_source_dirty_state(source: &Path) -> Result<SourceDirtyState> {
let output = git_command()
.args(["status", "--porcelain=v2", "-z", "--untracked-files=all"])
.current_dir(source)
.output()
.context("failed to run git status")?;
if !output.status.success() {
anyhow::bail!(
"git status failed: {}",
String::from_utf8_lossy(&output.stderr)
);
}
Ok(SourceDirtyState {
raw: Bytes::from(output.stdout),
})
}
/// Report from a sync operation.
#[derive(Clone, Debug, Default)]
pub struct SyncReport {
/// Whether HEAD was moved (git reset --hard was needed).
pub head_moved: bool,
/// Number of dirty files replicated from source.
pub dirty_files_copied: u64,
/// Number of files deleted in destination to match source deletions.View on GitHub (pinned to bc7f02eddd)
Solutions
- Run `git status` manually in `source` and read stderr — fix the underlying git error it reports.
- Remove a stale .git/index.lock if no git process is running.
- Verify the path passed is inside a git repository/worktree (git -C <source> rev-parse --is-inside-work-tree).
- Check git availability/version in PATH and any global hooks/config that could make status fail.
Example fix
// before: assume any dir works
let state = collect_source_dirty_state(&some_dir)?;
// after: validate first
if !Path::new(&some_dir).join(".git").exists() {
anyhow::bail!("{} is not a git repository", some_dir.display());
}
let state = collect_source_dirty_state(&some_dir)?; Defensive patterns
Strategy: try-catch
Validate before calling
let out = std::process::Command::new("git")
.args(["rev-parse", "--is-inside-work-tree"])
.current_dir(source)
.output()?;
if !out.status.success() || out.stdout.trim() != b"true" {
anyhow::bail!("{} is not a usable git worktree", source.display());
} Try / catch
match collect_source_dirty_state(source) {
Ok(state) => state,
Err(e) if e.to_string().contains("index.lock") => {
remove_stale_index_lock(source);
collect_source_dirty_state(source).context("git status failed after lock removal")?
}
Err(e) => return Err(e),
} Prevention
- Verify the path is a git repo before syncing
- Clean up stale .git/index.lock after crashed git processes
- Pin a known-good git version in the environment
- Avoid concurrent git operations on the same repo
When it happens
Trigger: Calling collect_source_dirty_state on a directory that is not a git repository (stderr: 'not a git repository'), a corrupt/locked index (index.lock exists), a repository with failing fsck/hook configuration, or git binary issues in the environment.
Common situations: Pointing the sync at a plain directory instead of a worktree; a crashed previous git process left .git/index.lock; the repo was cloned with Git LFS/SMIME config errors; PATH resolves to a broken or too-old git.
Related errors
- no .git file or directory found at {}
- git worktree add failed: {}
- git fetch --no-tags origin {spec} failed ({status}): {stderr
- merge of base ref '{base}' failed: {merge_out}
- merge of '{conv_branch}' into '{target_branch}' failed: {}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/31e8372fbb688c6b.
Report an issue: GitHub.