feat(stack): add `glab stack infer` command to create stack layers from a commit range

Summary

Adds glab stack infer - create stack layers from existing commits on your branch.

Instead of building a stack commit-by-commit with glab stack save, you can retroactively split an existing branch into a stack. The command opens your $EDITOR with a list of commits (like git rebase -i) where you choose which ones to include.

Usage

# Infer a stack from all commits between main and HEAD
glab stack infer main..HEAD
# With a stack name (skips the prompt)
glab stack infer --name my-feature main..HEAD
# From the last 3 commits
glab stack infer HEAD~3..HEAD

The editor opens with:
# Choose which commits you'd like to include in your stack.
# Lines starting with '#' will be ignored.
# Each line should contain only the commit hash you want to include.
# Remove or comment out commits you don't want in the stack.
#
# Commits are listed oldest to newest (stack order):
#
159e46f # feat: add cool thing (Gary Holtz)
cff60a3 # feat: add other cool thing (Gary Holtz)
c7a2022 # feat: but really add a super cool thing (Gary Holtz)

Comment out or delete lines to exclude commits. Each remaining commit becomes a stack layer.

How it works

Each layer is created by cherry-picking the selected commit onto a branch forked from the previous layer (or the base branch for the first layer). This produces the same structure as glab stack save, so glab stack sync works as expected. Each MR shows only its layer's diff. If there is a cherry-pick conflict (ex: non-contiguous commits that depend on skipped ones), the command aborts cleanly, rolls back all created branches and metadata, and reports which commit conflicted.

Caveats

  • DirectEditor is used instead of the huh widget. It opens the $EDITOR directly for the rebase-like UX rather than the inline huh textarea
  • The base branch is parsed from revision range: main..HEAD means the base is main, so cherry-picks apply cleanly
Edited by Gary Holtz

Merge request reports

Loading