{"record":{"id":"462fc1948921d054","repo":"gitbutlerapp/gitbutler","slug":"failed-to-find-reference-target-in-rebase-editor","errorCode":null,"errorMessage":"Failed to find reference {target} in rebase editor","messagePattern":"Failed to find reference (.+?) in rebase editor","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-rebase/src/graph_rebase/mutate.rs","lineNumber":249,"sourceCode":"        editor.select_reference(self.as_ref())\n    }\n}\n\n/// Operations for mutating the commit graph\nimpl<M: RefMetadata> Editor<'_, '_, M> {\n    /// Get a selector to a particular commit in the graph\n    pub fn select_commit(&self, target: gix::ObjectId) -> Result<Selector> {\n        match self.try_select_commit(target) {\n            Some(selector) => Ok(selector),\n            None => Err(anyhow!(\"Failed to find commit {target} in rebase editor\")),\n        }\n    }\n\n    /// Get a selector to a particular reference in the graph\n    pub fn select_reference(&self, target: &gix::refs::FullNameRef) -> Result<Selector> {\n        match self.try_select_reference(target) {\n            Some(selector) => Ok(selector),\n            None => Err(anyhow!(\n                \"Failed to find reference {target} in rebase editor\"\n            )),\n        }\n    }\n\n    /// Get a selector to a particular commit in the graph\n    pub fn try_select_commit(&self, target: gix::ObjectId) -> Option<Selector> {\n        for node_idx in self.graph.node_indices() {\n            if let Step::Pick(Pick { id, .. }) = self.graph[node_idx]\n                && id == target\n            {\n                return Some(self.new_selector(node_idx));\n            }\n        }\n\n        None\n    }\n","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-rebase/src/graph_rebase/mutate.rs#L231-L267","documentation":"`Editor::select_reference` looks up a reference by full name (e.g. `refs/heads/feature`) among the graph's steps and returns this error when the reference is not represented in the current rebase graph. Unborn branches, refs outside the workspace (e.g. `refs/remotes/...` tags or other remotes), or typos in the refname all miss. `try_select_reference` exists as the Option-returning probe.","triggerScenarios":"Calling `select_reference` with `refs/heads/new-branch` before it has any commits (unborn); selecting a remote-tracking or tag ref that was never added to the graph; passing a partial name like \"main\" instead of the full `refs/heads/main`.","commonSituations":"Workspace code selecting refs right after branch creation before a graph rebuild; mixing gix FullNameRef values from a different snapshot; ref deleted concurrently by another process (git CLI, another window).","solutions":["Use the full reference name (`refs/heads/<branch>`) as `gix::refs::FullNameRef` expects","Rebuild/refresh the editor graph after creating or deleting refs, then select","Use `try_select_reference` when the ref may legitimately be absent, and handle None","Check the ref still exists (`repo.find_reference`) to distinguish 'deleted concurrently' from 'not in graph'"],"exampleFix":"// before\nlet sel = editor.select_reference(name.as_ref())?; // Err: Failed to find reference ...\n\n// after\nuse anyhow::Context;\nlet sel = editor\n    .try_select_reference(name.as_ref())\n    .with_context(|| format!(\"reference {name} not in editor graph; rebuild graph after ref changes\"))?;","handlingStrategy":"validation","validationCode":"let name = gix::refs::FullName::try_from(format!(\"refs/heads/{branch}\"))\n    .with_context(|| format!(\"invalid ref name for branch {branch}\"))?;\nlet Some(sel) = editor.try_select_reference(name.as_ref()) else {\n    anyhow::bail!(\"reference {name} not in editor graph\");\n};","typeGuard":null,"tryCatchPattern":"match editor.select_reference(name.as_ref()) {\n    Ok(sel) => sel,\n    Err(e) if e.to_string().contains(\"Failed to find reference\") => {\n        anyhow::ensure!(repo.find_reference(name.as_str()).is_ok(),\n            \"reference {name} no longer exists (deleted concurrently)\");\n        rebuild_editor_and_retry(name)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always pass full refnames (refs/heads/...) as FullName/FullNameRef, never bare branch names","Rebuild the editor graph after creating or deleting refs before selecting","Use try_select_reference for refs that may legitimately be absent (e.g. unborn branches)"],"tags":["rust","git","graph-rebase","reference-not-found","refs"],"backgroundTag":"reference-not-found","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}