{"record":{"id":"ae189fbad06a2637","repo":"xai-org/grok-build","slug":"git-clean-failed","errorCode":null,"errorMessage":"git clean {} failed: {}","messagePattern":"git clean (.+?) failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-fast-worktree/src/git/checkout.rs","lineNumber":69,"sourceCode":"}\n\n/// Run `git clean -fd` (or `-fdx`) to remove untracked files and directories.\n///\n/// When `include_ignored` is `true`, also removes files covered by `.gitignore`\n/// (equivalent to `git clean -fdx`). This is useful when recycling worktrees\n/// in a pool, where leftover build artifacts must be purged.\n///\n/// This is a blocking operation.\npub(crate) fn git_clean_fd(worktree_path: &Path, include_ignored: bool) -> Result<()> {\n    let flags = if include_ignored { \"-fdx\" } else { \"-fd\" };\n    let output = git_command()\n        .current_dir(worktree_path)\n        .args([\"clean\", flags])\n        .output()\n        .context(\"failed to run git clean\")?;\n\n    if !output.status.success() {\n        anyhow::bail!(\n            \"git clean {} failed: {}\",\n            flags,\n            String::from_utf8_lossy(&output.stderr)\n        );\n    }\n\n    Ok(())\n}\n\n/// Run `git checkout <ref>`. Blocking.\npub(crate) fn checkout_ref(worktree_path: &Path, git_ref: &str) -> Result<()> {\n    let output = git_command()\n        .current_dir(worktree_path)\n        .args([\"checkout\", git_ref])\n        .output()\n        .context(\"failed to run git checkout\")?;\n\n    if !output.status.success() {","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-fast-worktree/src/git/checkout.rs#L51-L87","documentation":"`git_clean_fd` runs `git clean <flags>` in the worktree; a non-zero exit triggers this bail with the flags and git's stderr. The untracked-file cleanup step of a sync failed, so the worktree may still contain stale untracked files.","triggerScenarios":"Calling `sync_worktree_opts` / `sync_from_precomputed` when `git clean` fails — e.g. the worktree path isn't a valid git worktree, a nested repository blocks deletion, or file permissions prevent removal.","commonSituations":"Running clean with `-fd`/`-fdx` on directories containing root-owned or read-only files; nested git repos or submodules refusing deletion; Windows/permission issues or processes holding files open; corrupted worktree metadata.","solutions":["Read git's stderr in the error message to identify which path couldn't be removed.","Close processes holding files open and fix permissions (e.g. `chmod -R u+w`, or run with adequate privileges) then re-run the sync.","Handle nested repos: remove them manually or add them to `.gitignore`/exclusions so `git clean` doesn't try to delete them.","Verify the worktree is valid: `git -C <path> status` should succeed; repair with `git worktree repair` if not.","If untracked files matter, back them up before sync; if not, delete problem directories manually and retry."],"exampleFix":"// before\n// nested repo blocks: git clean -fd fails with 'Unable to remove ...'\nsync_worktree_opts(&worktree, &opts)?;\n// after\n// exclude nested repo before syncing\nrun_in(worktree, &[\"rm\", \"-rf\", \"vendor/nested-repo\"]);\nsync_worktree_opts(&worktree, &opts)?;\n","handlingStrategy":"validation","validationCode":"use std::process::Command;\nuse std::path::Path;\nfn cleanable(worktree: &Path) -> bool {\n    Command::new(\"git\").current_dir(worktree).args([\"status\", \"--porcelain\"])\n        .output().map(|o| o.status.success()).unwrap_or(false)\n}\nassert!(cleanable(worktree_path), \"not a valid git worktree\");","typeGuard":null,"tryCatchPattern":"match sync_worktree_opts(&worktree, &opts) {\n    Err(e) if e.to_string().contains(\"git clean\") => {\n        eprintln!(\"clean failed: {e}\"); // stderr embedded\n        // fix permissions / remove nested repos, then retry\n    }\n    r => r?,\n}","preventionTips":["Exclude nested git repos from worktrees or handle them separately","Ensure files are writable and no process holds them open during sync","Back up important untracked files before running clean-based syncs","Validate the worktree (git status) before each sync"],"tags":["git","clean","worktree","external-command"],"backgroundTag":"git-command-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}