{"record":{"id":"06a2edc81d83df8b","repo":"gitbutlerapp/gitbutler","slug":"stack-has-no-branches","errorCode":null,"errorMessage":"Stack has no branches","messagePattern":"Stack has no branches","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/legacy/absorb.rs","lineNumber":442,"sourceCode":"                candidate.hunk.path\n            );\n        }\n    }\n\n    // Priority 2: Use the candidate's stack ID if available\n    if let Some(stack_id) = candidate.stack_id {\n        let branch_ref = candidate.branch_ref.as_ref();\n\n        let stack_details = crate::legacy::workspace::stack_details(ctx, Some(stack_id))?;\n        if let Some(branch) = find_target_branch(&stack_details, branch_ref)\n            && let Some(commit) = branch.commits.first()\n        {\n            return Ok((stack_id, commit.id, AbsorptionReason::StackAssignment));\n        }\n\n        // If there are no commits in the target branch, create a blank commit first\n        let branch = find_target_branch(&stack_details, branch_ref)\n            .ok_or_else(|| anyhow::anyhow!(\"Stack has no branches\"))?;\n        commit_insert_blank_only_impl(\n            ctx,\n            RelativeTo::Reference(branch.reference.clone()),\n            InsertSide::Below,\n            DryRun::No,\n            perm,\n        )?;\n\n        // Fetch again to get the newly created commit\n        let stack_details = crate::legacy::workspace::stack_details(ctx, Some(stack_id))?;\n        if let Some(branch) = find_target_branch(&stack_details, branch_ref)\n            && let Some(commit) = branch.commits.first()\n        {\n            return Ok((stack_id, commit.id, AbsorptionReason::StackAssignment));\n        }\n\n        anyhow::bail!(\"Failed to create blank commit in stack: {stack_id:?}\");\n    }","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/2497b8007aa4a1922dae9a805b32ffe5b5037785/crates/but-api/src/legacy/absorb.rs#L424-L460","documentation":"In ensure_target_commit() priority 2: the candidate hunk is assigned to a stack (candidate.stack_id is Some), but that stack's details contain zero branch_details, so find_target_branch() — which falls back to branch_details.first() — finds no branch and there is no reference to insert a blank commit below. With any branch present this error cannot fire, even when branch_ref does not match.","triggerScenarios":"absorption_plan/absorb with a hunk assigned to a stack whose branch_details are empty: all segments anonymous or unapplied, or the stack was emptied while the file-assignment metadata persisted.","commonSituations":"All branches of the stack were unapplied or deleted while assignments to it remained; workspace metadata partially written or out of sync; another writer mutated the workspace between listing and absorbing.","solutions":["Reload the workspace and confirm the stack still lists at least one branch segment via stack_details","Re-apply or recreate a branch in that stack, or unassign the file so default routing applies","If the metadata is inconsistent, use GitButler workspace verification/repair or undo to a consistent oplog entry"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let details = workspace_stack_details(ctx, stack_id)?;\nif details.branch_details.is_empty() {\n    // stack cannot absorb: ask the user to re-apply a branch or unassign the file\n} else {\n    let plan = absorption_plan_with_perm(ctx, target, perm)?;\n}","typeGuard":"fn stack_has_branches(details: &StackDetails) -> bool {\n    !details.branch_details.is_empty()\n}","tryCatchPattern":null,"preventionTips":["Check stack_details for the assigned stack before offering absorb on its files","Unassign files when their stack's last branch is unapplied or deleted","Treat empty branch_details as invalid workspace state and repair it early"],"tags":["git","absorb","stack","branch-details","workspace"],"backgroundTag":"missing-branch-in-stack","analyzedSha":"2497b8007aa4a1922dae9a805b32ffe5b5037785","analyzedAt":"2026-08-17T00:30:25.648Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}