{"record":{"id":"157ca43815538497","repo":"gitbutlerapp/gitbutler","slug":"cannot-position-reference-below-unborn-segment","errorCode":null,"errorMessage":"Cannot position reference below unborn segment '{}'","messagePattern":"Cannot position reference below unborn segment '(.+?)'","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/but-transaction/src/lib.rs","lineNumber":568,"sourceCode":"                            but_workspace::branch::create_reference::Anchor::AtReference {\n                                ref_name,\n                                position,\n                            },\n                        ),\n                        None,\n                    )\n                } else {\n                    let oldest_commit_id = segment\n                        .commits\n                        .last()\n                        .map(|commit| commit.id)\n                        .or_else(|| {\n                            workspace\n                                .tip_commit_by_segment_id(segment.id)\n                                .map(|commit| commit.id)\n                        })\n                        .ok_or_else(|| {\n                            anyhow::anyhow!(\n                                \"Cannot position reference below unborn segment '{}'\",\n                                ref_name.shorten()\n                            )\n                        })?;\n                    (\n                        Some(but_workspace::branch::create_reference::Anchor::AtSegment {\n                            ref_name,\n                            position,\n                        }),\n                        Some(oldest_commit_id),\n                    )\n                }\n            }\n            anchor => (anchor, None),\n        };\n        let repo = self.repo().clone();\n        let branch_stack_orders = self\n            .inner","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-transaction/src/lib.rs#L550-L586","documentation":"While positioning a new/updated reference with create_reference, the code needed the oldest commit of the target segment (to anchor a 'below' placement) but the segment has no commits and no resolvable tip — an unborn segment. References cannot be placed below a segment that contains nothing.","triggerScenarios":"Calling reference creation/update with an anchor position Below against a segment that is empty (newly created branch whose first commit doesn't exist yet, or a segment whose tip lookup in workspace metadata returned None).","commonSituations":"Creating dependent branches in an order that leaves the anchor segment unborn (e.g. trying to insert a ref below a just-created empty branch); workspace metadata out of sync with the graph so tip_commit_by_segment_id finds nothing.","solutions":["Anchor the reference above the segment or against an explicit commit instead of Position::Below","Create the first commit on the target segment before placing references below it","If metadata looks wrong, reload/recompute the workspace graph so the segment's tip resolves"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// ensure the anchor segment actually has a commit before requesting a 'below' position\nlet has_commits = segment.commits.iter().any(|_| true)\n    || workspace.tip_commit_by_segment_id(segment.id).is_some();\nif !has_commits {\n    return Err(anyhow!(\"segment unborn — cannot place ref below; anchor above or by commit\"));\n}","typeGuard":"fn segment_is_born(ws: &but_graph::Workspace, segment_id: SegmentId) -> bool {\n    ws.tip_commit_by_segment_id(segment_id).is_some()\n}","tryCatchPattern":"match create_ref(...) {\n    Err(e) if e.to_string().contains(\"unborn segment\") => { /* fall back to Anchor::AtSegment { position: Above } or AtCommit */ }\n    r => r,\n}","preventionTips":["Never anchor Position::Below on freshly created, commit-less segments","Ensure the first commit lands on a new branch before stacking references under it","Keep workspace metadata in sync (re-traverse the graph) before placing refs"],"tags":["rust","git","refs","unborn-branch","but-transaction"],"backgroundTag":"invalid-ref-anchor","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}