xai-org/grok-build · error
git clean {} failed: {}
Error message
git clean {} failed: {} What it means
`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.
Source
Thrown at crates/codegen/xai-fast-worktree/src/git/checkout.rs:69
}
/// Run `git clean -fd` (or `-fdx`) to remove untracked files and directories.
///
/// When `include_ignored` is `true`, also removes files covered by `.gitignore`
/// (equivalent to `git clean -fdx`). This is useful when recycling worktrees
/// in a pool, where leftover build artifacts must be purged.
///
/// This is a blocking operation.
pub(crate) fn git_clean_fd(worktree_path: &Path, include_ignored: bool) -> Result<()> {
let flags = if include_ignored { "-fdx" } else { "-fd" };
let output = git_command()
.current_dir(worktree_path)
.args(["clean", flags])
.output()
.context("failed to run git clean")?;
if !output.status.success() {
anyhow::bail!(
"git clean {} failed: {}",
flags,
String::from_utf8_lossy(&output.stderr)
);
}
Ok(())
}
/// Run `git checkout <ref>`. Blocking.
pub(crate) fn checkout_ref(worktree_path: &Path, git_ref: &str) -> Result<()> {
let output = git_command()
.current_dir(worktree_path)
.args(["checkout", git_ref])
.output()
.context("failed to run git checkout")?;
if !output.status.success() {View on GitHub (pinned to bc7f02eddd)
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.
Example fix
// before // nested repo blocks: git clean -fd fails with 'Unable to remove ...' sync_worktree_opts(&worktree, &opts)?; // after // exclude nested repo before syncing run_in(worktree, &["rm", "-rf", "vendor/nested-repo"]); sync_worktree_opts(&worktree, &opts)?;
Defensive patterns
Strategy: validation
Validate before calling
use std::process::Command;
use std::path::Path;
fn cleanable(worktree: &Path) -> bool {
Command::new("git").current_dir(worktree).args(["status", "--porcelain"])
.output().map(|o| o.status.success()).unwrap_or(false)
}
assert!(cleanable(worktree_path), "not a valid git worktree"); Try / catch
match sync_worktree_opts(&worktree, &opts) {
Err(e) if e.to_string().contains("git clean") => {
eprintln!("clean failed: {e}"); // stderr embedded
// fix permissions / remove nested repos, then retry
}
r => r?,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- git reset --hard {} failed: {}
- git checkout {} failed: {}
- git worktree add failed: {}
- git worktree add failed: {}
- invalid .git file format: {}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/ae189fbad06a2637.
Report an issue: GitHub.