{"record":{"id":"b762497df387b7a4","repo":"astral-sh/ruff","slug":"git-checkout-of-commit-failed","errorCode":null,"errorMessage":"Git checkout of commit {} failed: {}","messagePattern":"Git checkout of commit (.+?) failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_benchmark/src/real_world_projects.rs","lineNumber":189,"sourceCode":"        .output()\n        .context(\"Failed to execute git fetch command\")?;\n\n    if !output.status.success() {\n        anyhow::bail!(\n            \"Git fetch of commit {} failed: {}\",\n            commit,\n            String::from_utf8_lossy(&output.stderr)\n        );\n    }\n\n    // Checkout specific commit\n    let output = Command::new(\"git\")\n        .args([\"checkout\", commit])\n        .current_dir(project_root)\n        .output()\n        .context(\"Failed to execute git checkout command\")?;\n\n    anyhow::ensure!(\n        output.status.success(),\n        \"Git checkout of commit {} failed: {}\",\n        commit,\n        String::from_utf8_lossy(&output.stderr)\n    );\n\n    Ok(())\n}\n\n/// Clone a git repository to the specified directory\nfn clone_repository(repo_url: &str, target_dir: &Path, commit: &str) -> Result<()> {\n    // Create parent directory if it doesn't exist\n    if let Some(parent) = target_dir.parent() {\n        std::fs::create_dir_all(parent).context(\"Failed to create parent directory for clone\")?;\n    }\n\n    // Clone with minimal depth and fetch only the specific commit\n    let output = Command::new(\"git\")","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/astral-sh/ruff/blob/672bb4edf04c84f8b0753346359daee4057158f2/crates/ruff_benchmark/src/real_world_projects.rs#L171-L207","documentation":"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.","triggerScenarios":"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.","commonSituations":"Interrupted benchmark runs leaving a dirty cache; someone edited files inside target/benchmark_cache; a fetch that partially failed before checkout.","solutions":["Delete the whole project cache directory (target/benchmark_cache/<name>) and rerun to get a clean clone","Check the embedded stderr: 'would be overwritten by checkout' means local modifications, missing object means the fetch above failed","Never manually edit files inside the benchmark cache"],"exampleFix":"# before\n bench run fails with: Git checkout of commit <sha> failed: ...\n\n# after\nrm -rf target/benchmark_cache/<project> && cargo bench --bench <real-world-bench>","handlingStrategy":"validation","validationCode":"# refuse to run on a dirty cache; reset it instead\ntest -z \"$(git -C \"$cache_dir\" status --porcelain)\" || rm -rf \"$cache_dir\"\ncargo bench --bench \"$bench\"","typeGuard":null,"tryCatchPattern":"match Command::new(\"git\").args([\"checkout\", commit]).current_dir(&root).output() {\n    Ok(out) if out.status.success() => Ok(()),\n    _ => {\n        std::fs::remove_dir_all(&root)?; // unrecoverable cache state: rebuild it\n        clone_repository(url, &root, commit)\n    }\n}","preventionTips":["Never edit files inside target/benchmark_cache","Treat checkout-after-fetch failures as cache corruption; remove and reclone","Keep benchmark runs interruptible without leaving dirty checkouts (kill between steps, not during)"],"tags":["benchmark","git","cache"],"backgroundTag":null,"analyzedSha":"672bb4edf04c84f8b0753346359daee4057158f2","analyzedAt":"2026-08-16T08:54:05.464Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}