astral-sh/ruff · error

Git fetch of commit {} failed: {}

Error message

Git fetch of commit {} failed: {}

What it means

The real-world-project benchmark harness caches cloned repos; on a cache hit it runs `git fetch origin <commit>` and bails with git's stderr when the fetch exits nonzero. The embedded stderr states the actual cause.

Source

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

    let cache_dir = target_dir.join("benchmark_cache").join(project_name);

    if let Some(parent) = cache_dir.parent() {
        std::fs::create_dir_all(parent).context("Failed to create cache directory")?;
    }

    Ok(cache_dir)
}

/// Update an existing repository
fn update_repository(project_root: &Path, commit: &str) -> Result<()> {
    let output = Command::new("git")
        .args(["fetch", "origin", commit])
        .current_dir(project_root)
        .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)

View on GitHub (pinned to 672bb4edf0)

Solutions

  1. Read the embedded git stderr first — it names the real failure (network, refspec, permissions)
  2. Delete the project cache under target/benchmark_cache/<name> to force a fresh clone
  3. Ensure the machine can reach the repo host over https (check proxy/firewall rules for git)
  4. Verify the pinned commit still exists upstream (e.g. GitHub commits page for that SHA)

Example fix

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

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

Strategy: retry

Validate before calling

# connectivity + commit sanity before benching
git ls-remote "$repo_url" HEAD >/dev/null 2>&1 || { echo "repo unreachable: $repo_url" >&2; exit 1; }
curl -fsS "https://api.github.com/repos/${repo_slug}/commits/$commit" >/dev/null || {
  echo "pinned commit $commit not found upstream" >&2; exit 1;
}

Try / catch

match update_repository(&project_root, commit) {
    Ok(()) => {}
    Err(err) if err.to_string().contains("Git fetch") => {
        std::fs::remove_dir_all(&project_root)?; // drop the cache, retry with a fresh clone
        clone_repository(repo_url, &project_root, commit)?;
    }
    Err(err) => return Err(err),
}

Prevention

When it happens

Trigger: Running `cargo bench` real-world benchmarks with an existing cache when the fetch fails: no network, a proxy blocking git, or the pinned commit not being fetchable from origin (rewritten/deleted history).

Common situations: Offline or proxied CI; upstream force-push removing the pinned commit; stale caches from an older benchmark revision.

Related errors


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