{"record":{"id":"33712888dcbc025a","repo":"GitoxideLabs/gitoxide","slug":"git-checkout-failed-with-337128","errorCode":null,"errorMessage":"git checkout failed with {}: {}","messagePattern":"git checkout failed with (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-tix/src/edit/time_travel.rs","lineNumber":1342,"sourceCode":"    )\n}\n\npub(super) fn checkout(workdir: &Path, args: impl IntoIterator<Item = OsString>) -> Result<()> {\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(workdir)\n        .arg(\"checkout\")\n        .args(args)\n        .output()\n        .context(\"could not launch git checkout\")?;\n    if output.status.success() {\n        return Ok(());\n    }\n    let stderr = output.stderr.trim().to_str_lossy();\n    if stderr.is_empty() {\n        anyhow::bail!(\"git checkout failed with {}\", output.status)\n    }\n    anyhow::bail!(\"git checkout failed with {}: {}\", output.status, stderr)\n}\n\nfn contains(repository: &gix::Repository, ancestor: ObjectId, descendant: ObjectId) -> bool {\n    ancestor == descendant\n        || repository\n            .merge_base(ancestor, descendant)\n            .is_ok_and(|base| base.as_ref() == ancestor)\n}\n\npub(crate) fn pin_label(pin: &history::Pin) -> String {\n    format!(\n        \"pin:{}\",\n        pin.name\n            .as_bstr()\n            .strip_prefix(history::PIN_PREFIX)\n            .unwrap_or(pin.name.as_bstr())\n            .to_str_lossy()\n    )","sourceCodeStart":1324,"sourceCodeEnd":1360,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/edit/time_travel.rs#L1324-L1360","documentation":"This variant of the `checkout` failure includes the captured stderr from the `git checkout` subprocess: tix ran `git checkout`, it exited non-zero, and stderr contained a message. The error propagates git's own diagnostic (e.g. 'error: pathspec ... did not match') alongside the exit status.","triggerScenarios":"Calling `checkout_review_return_reporting`, `checkout_branch`, `checkout_pin`, or `checkout_detached` with a ref/commit that git rejects — nonexistent branch, invalid object id, blocked by local modifications, or detached HEAD to an invalid pin.","commonSituations":"Typo in branch name; checking out a pin before it was created; uncommitted local changes colliding with the target ref; trying to checkout a commit not in the object database (shallow clone).","solutions":["Read the stderr in the error message — it contains git's exact reason — and fix that underlying issue.","Verify the target ref/commit exists with `git rev-parse <ref>` before checkout.","Commit or stash local modifications that git reports as blocking the checkout.","If the object is missing (shallow/partial clone), fetch it first (`git fetch --unshallow` or deepen)."],"exampleFix":"// before\ncheckout(&repo, &[\"checkout\", \"feature/typo-name\"])?;\n// -> \"git checkout failed with exit status: 1: error: pathspec 'feature/typo-name' did not match\"\n\n// after\nlet branch = \"feature/correct-name\";\nif repo.find_reference(&format!(\"refs/heads/{branch}\")).is_ok() {\n    checkout(&repo, &[\"checkout\", branch])?;\n}","handlingStrategy":"try-catch","validationCode":"repo.rev_parse_single(target)\n    .with_context(|| format!(\"target {target} does not resolve\"))?;\nif repo.is_dirty().unwrap_or(false) {\n    anyhow::bail!(\"commit or stash changes before checkout\");\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = checkout(&repo, &[\"checkout\", target]) {\n    let msg = e.to_string();\n    if let Some(stderr) = msg.splitn(2, \": \").nth(1) {\n        eprintln!(\"git said: {stderr}\"); // act on git's own diagnostic\n    }\n    return Err(e);\n}","preventionTips":["Read the stderr embedded in the error — it is git's exact reason","Resolve refs with `git rev-parse` before checkout","Stash or commit local modifications that collide with the target","Fetch missing objects in shallow/partial clones first"],"tags":["git","subprocess","checkout","external-command"],"backgroundTag":"git-command-failed","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}