{"record":{"id":"585436befe566679","repo":"gitbutlerapp/gitbutler","slug":"refusing-to-land-branch-with-whole-stack-it-585436","errorCode":null,"errorMessage":"Refusing to land `{branch}` with --whole-stack: it is not the top of its stack — unnamed segment(s) with commits sit above it (their branch refs no longer exist), so landing `{branch}` would not land the entire stack.","messagePattern":"Refusing to land `(.+?)` with --whole-stack: it is not the top of its stack — unnamed segment\\(s\\) with commits sit above it \\(their branch refs no longer exist\\), so landing `(.+?)` would not land the entire stack\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/land/mod.rs","lineNumber":416,"sourceCode":"    ctx: &mut Context,\n    branch: &str,\n    target_display: &str,\n    whole_stack: bool,\n) -> anyhow::Result<Vec<String>> {\n    let Some(scan) = scan_stack(ctx, branch)? else {\n        return Ok(Vec::new());\n    };\n\n    if whole_stack && scan.has_upper {\n        // Judge \"top of the stack\" by position, not by names: a segment whose branch ref was\n        // deleted still holds commits that \"land the entire stack\" would have to include.\n        if let Some(top) = scan.upper_segments.first() {\n            bail!(\n                \"Refusing to land `{branch}` with --whole-stack: it is not the top of its stack. \\\n                 --whole-stack lands the entire stack; name its top segment `{top}` instead.\",\n            );\n        }\n        bail!(\n            \"Refusing to land `{branch}` with --whole-stack: it is not the top of its stack — \\\n             unnamed segment(s) with commits sit above it (their branch refs no longer exist), so \\\n             landing `{branch}` would not land the entire stack.\",\n        );\n    }\n    // Key off the commits below, not the segment names: segments whose branch ref was deleted are\n    // unnamed but their commits would be published all the same.\n    let publishes_below = scan.commits_below > 0 || !scan.lower_segments.is_empty();\n    if publishes_below && !whole_stack {\n        if scan.lower_segments.is_empty() {\n            bail!(\n                \"Refusing to land `{branch}`: {} commit(s) on unnamed segment(s) below it would \\\n                 also be published to {target_display}. Pass --whole-stack to land `{branch}` \\\n                 together with everything below it.\",\n                scan.commits_below,\n            );\n        }\n        bail!(","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/land/mod.rs#L398-L434","documentation":"`validate_branch_landing` refuses a `--whole-stack` land when unnamed segments with commits sit above the branch — segments whose branch refs were deleted but which still hold commits. Since `--whole-stack` must land the entire stack, landing this branch would silently exclude those orphaned commits, so the operation is refused.","triggerScenarios":"Calling `branch_land` with `whole_stack: true` where `scan.has_upper` is true, `scan.upper_segments` is empty (no named top), but the graph shows unnamed segments with commits above the branch — typically after branch refs above were deleted without their commits being landed.","commonSituations":"Deleting an upper branch in the GitButler UI/CLI (or manually with `git branch -D`) and later trying to whole-stack-land a lower branch; workspace cleanup that removed refs while commits remained; stale stacks left from interrupted operations.","solutions":["Recreate or restore a branch on the orphaned upper commits so it has a name, then land that top segment with `--whole-stack`.","Inspect the workspace (`but branch list` / TUI) to find the unnamed commits and discard them if unneeded.","Land only this branch (without `--whole-stack`) if you intend to exclude the orphaned commits — but first confirm nothing depends on them."],"exampleFix":"// before\nbut land base-branch --whole-stack   // refused: unnamed segments with commits above\n// after\nbut branch create restored-top       # re-assign the orphaned commits to a named branch\nbut land restored-top --whole-stack","handlingStrategy":"validation","validationCode":"// ensure no orphaned (unnamed) commits exist above the branch before whole-stack landing\nconst ws = await api.workspaceState();\nconst unnamedAbove = ws.stacks.flatMap(s => s.segments)\n  .filter(seg => seg.position > positionOf(branch) && !seg.refName && seg.commitCount > 0);\nif (unnamedAbove.length) throw new Error('Restore or discard unnamed segments above before --whole-stack land');","typeGuard":"function hasUnnamedSegmentsAbove(segments, branchPos) {\n  return segments.some(s => s.position > branchPos && (s.refName == null) && s.commitCount > 0);\n}","tryCatchPattern":"try {\n  await api.land(branch, { wholeStack: true });\n} catch (e) {\n  if (String(e).includes('unnamed segment(s) with commits sit above')) {\n    await restoreOrDiscardOrphanedSegments(); // then retry\n  } else throw e;\n}","preventionTips":["Avoid deleting branch refs of unlanded commits; land or explicitly discard them first.","Periodically review the workspace for unnamed segments holding commits.","After any manual `git branch -D`, run `but status` and resolve orphaned commits before landing."],"tags":["git","stacked-branches","deleted-refs","validation"],"backgroundTag":"invalid-state-transition","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"}