gitbutlerapp/gitbutler · error
Cannot unapply anonymous segments yet even if they have a…
Error message
Cannot unapply anonymous segments yet even if they have a stack id
What it means
unapply_stack_v3 requires the stack's first segment to have a ref name (i.e. be an applied, named branch). If the first segment is anonymous (no ref_name), the code cannot derive branch names to unapply and bails, noting anonymous segments are not yet supported even when they carry a stack id.
Solutions
- Name the stack/branch first (assign a ref to the first segment) before unapplying
- Unapply via a different flow that supports anonymous segments (workspace-level operations)
- Check stack segments before calling and skip stacks whose first segment lacks a ref name
Example fix
// before
await unapplyStack(stackId);
// after
if (stack.segments[0]?.refName) {
await unapplyStack(stackId);
} else {
await nameStack(stackId, branchName); // then unapply
} Defensive patterns
Strategy: validation
Validate before calling
const stack = await getStack(projectId, stackId);
if (!stack.segments[0]?.refName) {
await nameStackBranch(projectId, stackId, 'my-branch');
}
await unapplyStack(projectId, stackId); Type guard
function hasNamedFirstSegment(stack) {
return Boolean(stack.segments?.[0]?.refName);
} Try / catch
try {
await unapplyStack(projectId, stackId);
} catch (e) {
if (String(e).includes('anonymous segments')) {
await assignBranchName(projectId, stackId);
await unapplyStack(projectId, stackId);
} else throw e;
} Prevention
- Give every stack a named branch before workspace operations
- Skip stacks whose first segment is anonymous when batch-unapplying
- Check segment refName presence before calling unapply APIs
When it happens
Trigger: Calling unapply_stack_v3_with_perm on a workspace stack whose first segment is anonymous (no branch ref), e.g. an unnamed/uncommitted-changes segment at the head of a lane.
Common situations: Unapplying a freshly created stack that was never assigned a branch name; workspace containing default/anonymous segments created by internal operations; invoking unapply on the workspace's implicit first lane.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- a committed transaction always materializes a workspace
- Branch ` ` is not part of the current workspace
- Cannot
- Cannot
- Commit is not in the applied workspace
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/3bcfcf2f7414a024.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-api/src/legacy/virtual_branches.rs:604
/// workspace: tip-most branch first, then branches closer to the workspace base.
fn stack_branch_names(
ctx: &mut Context,
stack_id: StackId,
perm: &RepoShared,
) -> Result<Vec<gix::refs::FullName>> {
let (_repo, ws, _) = ctx.workspace_and_db_with_perm(perm)?;
let Some(stack) = ws.stacks.iter().find(|stack| stack.id == Some(stack_id)) else {
return Err(
anyhow!("branch with ID {stack_id} not found").context(but_error::Code::BranchNotFound)
);
};
if stack
.segments
.first()
.is_none_or(|s| s.ref_name().is_none())
{
bail!("Cannot unapply anonymous segments yet even if they have a stack id");
}
Ok(stack
.segments
.iter()
.filter_map(|segment| {
segment
.ref_info
.as_ref()
.map(|ref_info| ref_info.ref_name.clone())
})
.collect())
}
/// Commit assigned worktree changes so they remain with the branch being unapplied.
///
/// `ctx` supplies repository, workspace, metadata, and diff settings used to
/// create the assignment commit. `branch` is the reference the new "WIPView on GitHub (pinned to 58e5313667)