{"record":{"id":"52aeb1c6809a9c9c","repo":"gitbutlerapp/gitbutler","slug":"expected-reference-selector-to-point-to-a-commit","errorCode":null,"errorMessage":"Expected reference selector to point to a commit","messagePattern":"Expected reference selector to point to a commit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/divergence.rs","lineNumber":185,"sourceCode":"            };\n            Ok((candidate_commit_id, relation))\n        })\n        .collect()\n}\n\nfn first_pick_parent<M: RefMetadata>(\n    editor: &Editor<'_, '_, M>,\n    selector: Selector,\n) -> Result<Selector> {\n    let mut adjacent = editor.direct_parents(selector)?;\n    adjacent.extend(editor.direct_children(selector)?);\n    adjacent.sort_by_key(|(_, order)| *order);\n    adjacent\n        .into_iter()\n        .find_map(|(candidate, _)| {\n            matches!(editor.lookup_step(candidate).ok()?, Step::Pick(_)).then_some(candidate)\n        })\n        .ok_or_else(|| anyhow::anyhow!(\"Expected reference selector to point to a commit\"))\n}\n\nfn tip_for_ref<M: RefMetadata>(\n    editor: &Editor<'_, '_, M>,\n    ref_name: &gix::refs::FullNameRef,\n    repo: &gix::Repository,\n) -> Result<Selector> {\n    let reference_selector = ref_name.to_selector(editor)?;\n    let head_id = repo.head_id()?.detach();\n    if let Some(child_on_head_path) =\n        child_on_head_first_parent_path(editor, reference_selector, head_id)?\n    {\n        return Ok(child_on_head_path);\n    }\n    first_pick_parent(editor, reference_selector).or_else(|_| {\n        let tip = repo.find_reference(ref_name)?.id().detach();\n        editor.select_commit(tip)\n    })","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/divergence.rs#L167-L203","documentation":"Raised by `first_pick_parent` in crates/but-workspace/src/divergence.rs:185 while walking adjacent reference selectors to find one whose lookup step is a `Pick`. If no adjacent candidate resolves to a pick step, the function concludes the selector does not point to a commit and errors. Exposed via `tip_for_ref`.","triggerScenarios":"Computing divergence for a reference whose selector history contains no `Pick` steps — e.g. the ref points at a non-commit object or the editor's step log lacks pick entries for adjacent candidates.","commonSituations":"Refs pointing at tags or blobs instead of commits; workspace metadata out of sync with the underlying repository; internal state corruption after interrupted operations.","solutions":["Verify the reference resolves to a commit (`peel to commit`) before computing divergence","Rebuild/refresh workspace metadata so the editor's step log matches the repository state","Check the branch was created by a supported operation (not hand-edited refs)","Report as a bug if a normal branch triggers it — this usually indicates an invariant violation"],"exampleFix":"// before\nlet tip = tip_for_ref(&editor, ref_name, &repo)?;\n// after\nlet commit = repo.find_reference(ref_name)?.peel_to_commit()?;\nlet tip = tip_for_ref(&editor, ref_name, &repo)?;","handlingStrategy":"validation","validationCode":"let commit = repo.find_reference(ref_name)?.peel_to_commit()\n    .context(\"ref does not point to a commit; divergence cannot be computed\")?;","typeGuard":null,"tryCatchPattern":"match tip_for_ref(&editor, ref_name, &repo) {\n    Err(e) if e.to_string().contains(\"Expected reference selector\") => refresh_workspace_state_and_retry(),\n    other => other?,\n}","preventionTips":["Only compute divergence for refs that peel to commits","Avoid hand-editing refs; use supported branch operations","Rebuild workspace metadata if operations were interrupted"],"tags":["git","internal","divergence"],"backgroundTag":"internal-invariant-violation","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}