{"record":{"id":"85f579c265b84bb3","repo":"gitbutlerapp/gitbutler","slug":"stack-name-stack-is-ambiguous-in-the-current-w","errorCode":null,"errorMessage":"Stack name '{stack}' is ambiguous in the current workspace","messagePattern":"Stack name '(.+?)' is ambiguous in the current workspace","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/but-debug/src/command/api.rs","lineNumber":89,"sourceCode":"                    || ref_name.shorten().as_bstr() == name.as_bytes()\n            })\n        })\n    }\n    if let Ok(stack_id) = stack.parse::<StackId>() {\n        return Ok(stack_id);\n    }\n\n    let (_guard, _repo, workspace, _db) = ctx.workspace_and_db()?;\n    let mut matches = workspace.stacks.iter().filter_map(|workspace_stack| {\n        stack_matches(workspace_stack, stack)\n            .then_some(workspace_stack.id)\n            .flatten()\n    });\n    let Some(stack_id) = matches.next() else {\n        bail!(\"Could not resolve stack '{stack}' by UUID or workspace branch name\");\n    };\n    if matches.next().is_some() {\n        bail!(\"Stack name '{stack}' is ambiguous in the current workspace\");\n    }\n    Ok(stack_id)\n}\n","sourceCodeStart":71,"sourceCodeEnd":93,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-debug/src/command/api.rs#L71-L93","documentation":"In `resolve_stack_id()`, after finding a first stack whose branch name matches, a second distinct match means the same name occurs in multiple stacks — unapply needs a unique target, so the command refuses. Matching compares full and shortened ref names per segment, so `main` matches both `refs/heads/main` and any other stack whose segment shortens to `main`.","triggerScenarios":"Two workspace stacks each containing a segment whose ref name shortens to the same branch name (e.g. the same branch attached to two stacks, or identically named branches in different remotes/segments) while resolving by name instead of UUID.","commonSituations":"A branch detached from one stack and attached to another leaving both in the workspace; duplicated stacks from recovery/sync operations; user assuming short names are unique.","solutions":["Use the stack UUID instead of the name — it bypasses name matching entirely.","Use the fully qualified ref (`refs/heads/<branch>`) if only one stack carries the full name.","Remove or rename the duplicate stack/branch so names become unique.","Run `but api branch-list` to see which stacks collide on the name."],"exampleFix":"# before\nbut api unapply-stack main   # two stacks have a segment shortening to 'main'\n\n# after\nbut api branch-list           # copy the intended stack's UUID\nbut api unapply-stack 550e8400-e29b-41d4-a716-446655440000","handlingStrategy":"validation","validationCode":"# Shell — count matches before unapply; require exactly one\ngrep -c \"name: <branch>\" <(but api branch-list)   # must print 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to UUIDs in scripts to sidestep name ambiguity entirely.","Use fully qualified ref names when names could repeat across stacks.","Clean up duplicate stacks (from sync/recovery events) as soon as branch-list shows the same name twice."],"tags":["stack","cli","ambiguity","identifier-resolution"],"backgroundTag":"ambiguous-identifier","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}