feat(stack): properly update branches on stack reorder and add guards rebase in-progress
Description
glab stack reorder only rewrote the stack ref files and retargeted the MR base branches; it never rebased the underlying Git branches. So after moving a diff to a new position, the MRs pointed at the right bases but the commits stayed put: the first branch ended up containing every diff in the stack, and every MR was out of whack.
This MR makes reorder actually restack the branches. Because a reorder now rewrites Git history (and can hit conflicts partway through), a stack can be "mid-reorder" for the first time. This MR also adds a resumable flow and guards so that in-progress state can't corrupt the stack.
- Rebase on reorder — each branch is rebased onto its new parent (
rebase --onto) so local history matches the chosen order, then each MR is retargeted onto the branch now preceding it. - Conflicts handled during reorder — reorder progress is persisted to a state file. On a conflict the command explains how to resolve it, and
glab stack reorder --continue/--abortfinish or fully roll back the reorder (restoring original branch tips, ref files, and the original branch).reorderalso refuses to start a second reorder while one is in progress. - Guards for in-progress state — a shared
CheckNoRebaseInProgresshelper blockscreate,infer,save,amend, andsyncwhile a reorder is paused or a Git rebase is active, with actionable error messages (Git alone doesn't reliably block these mid-rebase, e.g.commit --amendsucceeds once the index is clean). stack listreminder — warns (on stderr, so it stays out of piped output) that the listed order may be stale while a reorder is paused, without blocking the read-only command.
Related Issues
Resolves #8209
How has this been tested?
Unit tests were added covering the new behavior:
stack_reorder_test.go— the reorder rebase flow,--continue,--abort, and the already-in-progress guard.stackutils_test.go—CheckNoRebaseInProgressfor both the paused-reorder and active-rebase cases.stack_list_test.go— the paused-reorder reminder.git_test.go/stacked_test.go— the reorder-state read/write helpers andReorderInProgress/RebaseInProgressdetection.
Additionally, tested manually through common use cases to ensure working as expected.
Screenshots (if appropriate):
Closes #8209
Disclaimer: I am not a Go dev by trade. Claude was used heavily to draft MR.