Add a command to remove completed or abandoned stacks
Problem to solve
As a glab stack user, I want to remove a completed or abandoned stack from the local stack registry, so that glab stack switch only shows stacks that I can still work on.
glab stack sync removes layers whose merge requests were merged or closed. When the last layer is removed, the stack directory and its BASE_BRANCH file remain under .git/stacked/<stack-name>/. glab stack switch continues to show that empty stack because it discovers stacks from the directories under .git/stacked/.
The CLI does not provide a command to remove the remaining stack metadata. Users must know about the internal storage format and manually remove the directory.
Proposal
Add a command that removes a stack from the local registry:
glab stack delete <stack-name>The command should:
- Remove
.git/stacked/<stack-name>/. - Clear or update
glab.currentstackwhen it refers to the deleted stack. - Explain that it removes local stack metadata and does not delete remote branches or merge requests.
- Ask for confirmation unless a non-interactive confirmation flag is supplied.
As an additional cleanup measure, glab stack sync could remove a stack automatically after it removes the final merged or closed layer. Explicit deletion would still be useful for abandoned stacks.
Further details
One way to reproduce the stale entry is:
- Create and sync a stack.
- Merge all merge requests in the stack.
- Run
glab stack syncso that it removes the merged layers. - Run
glab stack switch.
The completed stack is still available in the selector. Its directory contains only BASE_BRANCH:
.git/stacked/<stack-name>/BASE_BRANCHThe current workaround is:
rm -r .git/stacked/<stack-name>This behavior was reproduced with glab 1.116.0.