{"record":{"id":"2498803d65afa307","repo":"GitoxideLabs/gitoxide","slug":"could-not-inspect-a-reference-before-rebasing-er","errorCode":null,"errorMessage":"could not inspect a reference before rebasing: {err}","messagePattern":"could not inspect a reference before rebasing: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-tix/src/edit/rebase.rs","lineNumber":2987,"sourceCode":"            if old == new {\n                continue;\n            }\n            if let (Some(old), Some(new)) = (old, new) {\n                ref_rewrites.push(RefRewrite {\n                    name: name.clone(),\n                    old,\n                    new,\n                });\n            }\n            edits.push(ref_edit(name.clone(), old, new));\n            rollback.push(ref_edit(name, new, old));\n        }\n    } else if !unborn {\n        for reference in repo.references()?.all()? {\n            let reference = match reference {\n                Ok(reference) => reference,\n                Err(err) if is_missing_ref(&*err) => continue,\n                Err(err) => anyhow::bail!(\"could not inspect a reference before rebasing: {err}\"),\n            };\n            if matches!(\n                reference.name().category(),\n                Some(Category::Tag | Category::RemoteBranch)\n            ) || super::undo::is_queue_ref(reference.name().as_bstr())\n            {\n                continue;\n            }\n            let Some(old) = reference.try_id().map(gix::Id::detach) else {\n                continue;\n            };\n            let Some(new) = rewritten.get(&old) else { continue };\n            let name = reference.name().to_owned();\n            if delete_refs.iter().any(|(delete, _)| delete == &name) {\n                continue;\n            }\n            if let Some(new) = *new {\n                ref_rewrites.push(RefRewrite {","sourceCodeStart":2969,"sourceCodeEnd":3005,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/edit/rebase.rs#L2969-L3005","documentation":"Before performing a rebase, the code snapshots all references it may need for undo/restore. If reading a reference returns an unexpected error that is not simply a missing reference (which is tolerated via `continue`), the operation aborts with this contextual message wrapping `{err}`.","triggerScenarios":"Calling a rebase edit when `repo.references()?.all()?` yields a reference whose `reference.name()` / peeling returns a real `Err` other than a missing-reference error (e.g. corrupt ref file, unreadable packed-refs entry, lock contention).","commonSituations":"Repositories with partially corrupted or hand-edited `.git/refs` files; concurrent git processes leaving stale `.lock` files; network remotes whose refs cannot be read at rebase time.","solutions":["Inspect the wrapped `{err}` in the message to identify the underlying ref error and fix the repository state (e.g. remove stale `.lock` files).","Run `git fsck` / `git pack-refs --all` to repair or consolidate refs.","Delete or repair the specific broken ref file under `.git/refs`/packed-refs.","Retry the rebase after no other git process is concurrently writing refs."],"exampleFix":"// after diagnosing the wrapped err\nlet stale = repo.git_dir().join(\"refs/heads/broken.lock\");\nif stale.exists() { std::fs::remove_file(&stale).ok(); }\nrepo.references()?.all()?.for_each(|r| { let _ = r?; Ok::<_, anyhow::Error>(()) })?; // verify all readable\nedit.rebase(...)?;","handlingStrategy":"try-catch","validationCode":"// ensure every ref is readable before rebasing\nfor refr in repo.references()?.all()? {\n    refr.map_err(|e| anyhow::anyhow!(\"unreadable ref before rebase: {e}\"))??;\n}\n","typeGuard":null,"tryCatchPattern":"match edit::rebase::perform(repo, plan) {\n    Err(e) if e.to_string().contains(\"could not inspect a reference\") => {\n        repair_refs(repo)?; // e.g. drop stale .lock files, pack-refs\n        edit::rebase::perform(repo, plan)\n    }\n    other => other,\n}\n","preventionTips":["Avoid running ref-writing git processes concurrently with edits","Clean stale `*.lock` files under `.git/refs` after crashes","Periodically run `git fsck` to catch ref corruption early"],"tags":["refs","rebase","git","io"],"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"}