{"record":{"id":"6dcad74b52dbd22e","repo":"GitoxideLabs/gitoxide","slug":"git-checkout-failed-with","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":1340,"sourceCode":"        workdir,\n        [OsString::from(\"--detach\"), OsString::from(id.to_hex().to_string())],\n    )\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())","sourceCodeStart":1322,"sourceCodeEnd":1358,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/edit/time_travel.rs#L1322-L1358","documentation":"The `checkout` helper shells out to `git checkout`; when the subprocess exits with a nonzero status and its stderr is empty, tix reports only the process exit status because there is no stderr text to include. It surfaces that the external git command failed, without a diagnostic message.","triggerScenarios":"Calling `checkout_review_return_reporting`, `checkout_branch`, `checkout_pin`, or `checkout_detached` when the spawned `git checkout` fails (non-success exit code) and produces no stderr output, e.g. git died abnormally or was killed.","commonSituations":"Checkout of a ref that doesn't exist where git's message went to stdout; git interrupted by a signal; odd git versions writing diagnostics elsewhere; a corrupted repository making git fail silently.","solutions":["Run the same `git checkout <args>` manually in the repo to see the real failure.","Verify the branch/pin/review ref you are checking out actually exists (`git branch -a`, `git rev-parse <ref>`).","Check `git status` for a dirty worktree blocking checkout and stash or commit first.","Update git or check for repository corruption with `git fsck`."],"exampleFix":"// before\ncheckout(&repo, &[\"checkout\", \"missing-branch\"])?;\n// -> \"git checkout failed with exit status: 1\"\n\n// after\nif repo.rev_parse_single(\"refs/heads/missing-branch\").is_err() {\n    eprintln!(\"branch does not exist\");\n} else {\n    checkout(&repo, &[\"checkout\", \"missing-branch\"])?;\n}","handlingStrategy":"try-catch","validationCode":"// verify the ref resolves and the worktree is clean before checkout\nrepo.rev_parse_single(&format!(\"refs/heads/{branch}\"))\n    .context(\"branch does not exist\")?;\nif !repo.is_dirty().unwrap_or(false) { checkout(&repo, &[\"checkout\", branch])?; }","typeGuard":null,"tryCatchPattern":"if let Err(e) = checkout(&repo, &[\"checkout\", target]) {\n    let msg = e.to_string();\n    if msg.contains(\"git checkout failed with exit\") && !msg.contains(\": \") {\n        // no stderr: rerun git checkout manually to capture the real cause\n    }\n    return Err(e.context(\"checkout failed\"));\n}","preventionTips":["Confirm the target ref exists before checkout","Keep the worktree clean (commit/stash) before switching","Pin the git version used by tix and CI to avoid silent failures","Run `git fsck` if checkout fails without diagnostics"],"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"}