feat(cli): prune local branches with no worktree - #99
Draft
lettertwo wants to merge 3 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
When a stack of two or more PRs merges while a worktree has one of the stack's branches checked out,
git workon pruneremoves that worktree and deletes its branch, then stops. The other branches in the stack stay behind as local branches, sincepruneonly ever considered branches through the worktree that had them checked out.This problem is compounded for gh-stack users: gh-stack does not configure upstreams on branches, and a squash merge makes it impossible to tell when a branch was merged. As a result, PR merge status is the only reliable signal that can reach a merged stack's leftovers, which to date has not factored into any pruning decisions.
Change
This PR adds branch-only rows to
prune. Every local branch with no worktree (minus the default branch, protected globs, and any branch checked out in a worktree, including the default one) joins the candidate pool and is evaluated for the same signals as a worktree row:PrMergedalways,RemoteGoneunder--gone,Mergedunder--merged.--no-branchesorworkon.pruneBranches = falseopts out.--keep-branchdrops branch rows entirely.(no worktree)in dry-run and carry ano worktree, ...annotation in the picker. Prompts and the success line count worktrees and branches separately.--jsonentries gain"kind": "worktree" | "branch", and a branch row'spathisnull.--force" rule for a healthy one.Stack created with GitHub Stacks CLI • Give Feedback 💬