astral-sh/ruff · error

Git checkout of commit {} failed: {}

Error message

Git checkout of commit {} failed: {}

What it means

After updating a cached repository to the pinned commit, the benchmark harness runs `git checkout <commit>` and fails when checkout exits nonzero, embedding git's stderr. This operates on the cache under target/benchmark_cache, not your source tree.

Source

Thrown at crates/ruff_benchmark/src/real_world_projects.rs:189

        .output()
        .context("Failed to execute git fetch command")?;

    if !output.status.success() {
        anyhow::bail!(
            "Git fetch of commit {} failed: {}",
            commit,
            String::from_utf8_lossy(&output.stderr)
        );
    }

    // Checkout specific commit
    let output = Command::new("git")
        .args(["checkout", commit])
        .current_dir(project_root)
        .output()
        .context("Failed to execute git checkout command")?;

    anyhow::ensure!(
        output.status.success(),
        "Git checkout of commit {} failed: {}",
        commit,
        String::from_utf8_lossy(&output.stderr)
    );

    Ok(())
}

/// Clone a git repository to the specified directory
fn clone_repository(repo_url: &str, target_dir: &Path, commit: &str) -> Result<()> {
    // Create parent directory if it doesn't exist
    if let Some(parent) = target_dir.parent() {
        std::fs::create_dir_all(parent).context("Failed to create parent directory for clone")?;
    }

    // Clone with minimal depth and fetch only the specific commit
    let output = Command::new("git")

View on GitHub (pinned to 672bb4edf0)

Solutions

  1. Delete the whole project cache directory (target/benchmark_cache/<name>) and rerun to get a clean clone
  2. Check the embedded stderr: 'would be overwritten by checkout' means local modifications, missing object means the fetch above failed
  3. Never manually edit files inside the benchmark cache

Example fix

# before
 bench run fails with: Git checkout of commit <sha> failed: ...

# after
rm -rf target/benchmark_cache/<project> && cargo bench --bench <real-world-bench>
Defensive patterns

Strategy: validation

Validate before calling

# refuse to run on a dirty cache; reset it instead
test -z "$(git -C "$cache_dir" status --porcelain)" || rm -rf "$cache_dir"
cargo bench --bench "$bench"

Try / catch

match Command::new("git").args(["checkout", commit]).current_dir(&root).output() {
    Ok(out) if out.status.success() => Ok(()),
    _ => {
        std::fs::remove_dir_all(&root)?; // unrecoverable cache state: rebuild it
        clone_repository(url, &root, commit)
    }
}

Prevention

When it happens

Trigger: The cached checkout has local modifications (a previous run left changes behind), or the fetched commit object is missing so checkout cannot resolve the ref.

Common situations: Interrupted benchmark runs leaving a dirty cache; someone edited files inside target/benchmark_cache; a fetch that partially failed before checkout.

Related errors


AI-assisted analysis of astral-sh/ruff@672bb4edf0 (2026-08-16). Data as JSON: /api/errors/b762497df387b7a4. Report an issue: GitHub.