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.currentstack when 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:

  1. Create and sync a stack.
  2. Merge all merge requests in the stack.
  3. Run glab stack sync so that it removes the merged layers.
  4. Run glab stack switch.

The completed stack is still available in the selector. Its directory contains only BASE_BRANCH:

.git/stacked/<stack-name>/BASE_BRANCH

The current workaround is:

rm -r .git/stacked/<stack-name>

This behavior was reproduced with glab 1.116.0.

Edited by Mathew Wheatley