{"record":{"id":"31e8372fbb688c6b","repo":"xai-org/grok-build","slug":"git-status-failed","errorCode":null,"errorMessage":"git status failed: {}","messagePattern":"git status failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-fast-worktree/src/sync.rs","lineNumber":71,"sourceCode":"    }\n}\n\n/// Collect dirty state from a source repository.\n///\n/// Runs `git status --porcelain=v2 -z --untracked-files=all` on the source\n/// and captures the output. The result can be shared across multiple\n/// [`WorktreeSync::sync_from_precomputed`] calls.\n///\n/// This is a **blocking** function — call from `spawn_blocking` in async contexts.\npub fn collect_source_dirty_state(source: &Path) -> Result<SourceDirtyState> {\n    let output = git_command()\n        .args([\"status\", \"--porcelain=v2\", \"-z\", \"--untracked-files=all\"])\n        .current_dir(source)\n        .output()\n        .context(\"failed to run git status\")?;\n\n    if !output.status.success() {\n        anyhow::bail!(\n            \"git status failed: {}\",\n            String::from_utf8_lossy(&output.stderr)\n        );\n    }\n\n    Ok(SourceDirtyState {\n        raw: Bytes::from(output.stdout),\n    })\n}\n\n/// Report from a sync operation.\n#[derive(Clone, Debug, Default)]\npub struct SyncReport {\n    /// Whether HEAD was moved (git reset --hard was needed).\n    pub head_moved: bool,\n    /// Number of dirty files replicated from source.\n    pub dirty_files_copied: u64,\n    /// Number of files deleted in destination to match source deletions.","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-fast-worktree/src/sync.rs#L53-L89","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: assume any dir works\nlet state = collect_source_dirty_state(&some_dir)?;\n// after: validate first\nif !Path::new(&some_dir).join(\".git\").exists() {\n    anyhow::bail!(\"{} is not a git repository\", some_dir.display());\n}\nlet state = collect_source_dirty_state(&some_dir)?;","handlingStrategy":"try-catch","validationCode":"let out = std::process::Command::new(\"git\")\n    .args([\"rev-parse\", \"--is-inside-work-tree\"])\n    .current_dir(source)\n    .output()?;\nif !out.status.success() || out.stdout.trim() != b\"true\" {\n    anyhow::bail!(\"{} is not a usable git worktree\", source.display());\n}","typeGuard":null,"tryCatchPattern":"match collect_source_dirty_state(source) {\n    Ok(state) => state,\n    Err(e) if e.to_string().contains(\"index.lock\") => {\n        remove_stale_index_lock(source);\n        collect_source_dirty_state(source).context(\"git status failed after lock removal\")?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["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"],"tags":["git","subprocess","filesystem"],"backgroundTag":"git-command-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}