{"record":{"id":"0b576248b1383e19","repo":"gitbutlerapp/gitbutler","slug":"could-not-find-a-segment-named-in-workspace","errorCode":null,"errorMessage":"Could not find a segment named '{}' in workspace","messagePattern":"Could not find a segment named '(.+?)' in workspace","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/create_reference.rs","lineNumber":328,"sourceCode":"                position,\n            }) => {\n                let mut validate_id = true;\n                let ref_target_id = if workspace.has_metadata() {\n                    let (stack_idx, seg_idx) =\n                        workspace.try_find_segment_owner_indexes_by_refname(anchor_ref.as_ref())?;\n                    let segment = &workspace.stacks[stack_idx].segments[seg_idx];\n\n                    workspace\n                        .tip_commit_by_segment_id(segment.id)\n                        .map(|commit| position.resolve_commit(commit.into(), ws_base))\n                        .context(\n                            \"BUG: we should always see through to the base or eligible commits\",\n                        )??\n                } else {\n                    let Some((_stack, segment)) =\n                        workspace.find_segment_and_stack_by_refname(anchor_ref.as_ref())\n                    else {\n                        bail!(\n                            \"Could not find a segment named '{}' in workspace\",\n                            anchor_ref.shorten()\n                        );\n                    };\n                    position.resolve_commit(\n                        segment\n                            .commits\n                            .first()\n                            .context(\"Cannot create reference on unborn branch\")?\n                            .into(),\n                        ws_base,\n                    )?\n                };\n                let points_to_workspace_base = Some(ref_target_id) == ws_base;\n                if points_to_workspace_base {\n                    validate_id = false;\n                }\n                // The lower bound owns no commits, so an ad-hoc workspace needs explicit ref","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/create_reference.rs#L310-L346","documentation":"When creating a reference with an anchor (`anchor_ref`) that positions the new branch, the workspace must contain a segment matching the anchor. If `find_segment_and_stack_by_refname` finds nothing, create_reference cannot resolve the anchor commit and bails.","triggerScenarios":"Calling `create_reference` with `anchor_ref` set to a refname that is not part of the target workspace — e.g. a branch on another workspace, an unapplied branch, or a typo.","commonSituations":"Anchoring a new branch on a branch that was since unapplied or deleted; using a fully-qualified ref from outside the current workspace; UI/script passing stale branch names.","solutions":["Pick an anchor ref that is currently applied in the workspace (check workspace segments first)","Apply the anchor branch to the workspace before creating the reference on top of it","Fix the anchor refname (verify it exists in the workspace listing)"],"exampleFix":"// before\ncreate_reference(meta, repo, \"new-branch\", target, anchor: \"old-branch\")?;\n// after\nassert!(workspace.find_segment_and_stack_by_refname(\"refs/heads/old-branch\").is_some());\ncreate_reference(meta, repo, \"new-branch\", target, anchor: \"old-branch\")?;","handlingStrategy":"validation","validationCode":"if workspace.find_segment_and_stack_by_refname(anchor_ref.as_ref()).is_none() {\n    return Err(format!(\"anchor {} not in workspace\", anchor_ref.shorten()));\n}","typeGuard":"fn is_workspace_segment(ws: &Workspace, r: &gix::refs::Reference) -> bool {\n    ws.find_segment_and_stack_by_refname(r.as_ref()).is_some()\n}","tryCatchPattern":"match create_reference(...) {\n    Err(e) if e.to_string().contains(\"Could not find a segment named\") => /* choose a valid anchor */,\n    Err(e) => return Err(e.into()),\n    Ok(r) => r,\n}","preventionTips":["Pick anchors from the workspace's current segment list","Re-read workspace state before each create_reference call","Avoid anchoring on branches that may be unapplied concurrently"],"tags":["git","workspace","anchor"],"backgroundTag":"entity-not-found","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"}