{"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":null,"httpStatus":null,"severity":"error","filePath":"crates/but-transaction/src/lib.rs","lineNumber":617,"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":599,"sourceCodeEnd":635,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-transaction/src/lib.rs#L599-L635","documentation":"When creating a reference positioned below a workspace segment, `create_reference` needs an existing tip commit for that segment to anchor against. If the segment has no commits (unborn — neither a ref-derived tip nor any tip commit by segment id), it cannot anchor the new reference and errors with the shortened ref name.","triggerScenarios":"Calling create_reference with an anchor at a segment that has never been committed to (freshly created branch with zero commits, or a segment whose tip lookup fails).","commonSituations":"Creating references below a just-initialized, empty branch; racing reference creation before the first commit lands on the segment; refs created pointing at unborn HEAD on a new repository.","solutions":["Commit at least once on the target segment before anchoring a reference below it","Anchor the reference at a different, existing segment or at a commit id instead","Wait for/retry after the segment's first commit materializes","Validate the segment has a tip commit (tip_commit_by_segment_id) before creating the reference"],"exampleFix":"// before\nif segment.tip_commit_by_segment_id(id).is_none() {\n    return Err(anyhow!(\"segment {id} is unborn\"));\n}\ntx.create_reference(&ref_name, anchor)?;\n// after\nmatch segment.tip_commit_by_segment_id(id) {\n    Some(_) => tx.create_reference(&ref_name, anchor)?,\n    None => tracing::warn!(\"skipping reference {ref_name}: segment unborn\"),\n}","handlingStrategy":"validation","validationCode":"fn segment_is_born(ws: &Workspace, segment_id: SegmentId) -> bool {\n    ws.tip_commit_by_segment_id(segment_id).is_some()\n}\n// guard: assert!(segment_is_born(&ws, seg.id));","typeGuard":null,"tryCatchPattern":"match tx.create_reference(&name, anchor) {\n    Err(e) if format!(\"{e:#}\").starts_with(\"Cannot position reference below unborn segment\") => {\n        tracing::warn!(\"{e:#}; deferring reference creation\");\n        defer_until_segment_has_commit(&name, anchor)\n    }\n    r => r?,\n}","preventionTips":["Create references only after the target segment has at least one commit","Anchor at an explicit commit id when segments may be unborn","Check tip_commit_by_segment_id before building segment anchors"],"tags":["git","reference","workspace","unborn"],"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"}