Repository navigation
Skip branches checked out in linked worktrees during pruning - #22004
Merged
niik merged 4 commits intoMay 11, 2026
Merged
Conversation
The BranchPruner deletes local branches that are merged and whose upstream is gone. It already skips reserved branches, the current branch, and recently checked out branches — but it has no awareness of git worktrees. A branch checked out in a linked worktree would be deleted, leaving that worktree in a broken state. Add `getWorktreeCheckedOutBranches` which parses `git worktree list --porcelain` and returns the set of canonical refs checked out in linked worktrees. The pruner now excludes these refs from deletion. Fixes #8043
Contributor
|
Thanks for your pull request! Unfortunately, it doesn't meet the minimum requirements for review:
Please update your PR to address the above. Requirements:
This PR will be automatically closed in 7 days if these requirements are not met. |
Parse git worktree list --porcelain output using NUL delimiters instead of newlines, making it safe for paths containing special characters. Co-authored-by: Copilot <[email protected]>
The function name implies it returns all worktree-checked-out branches. Excluding the main worktree was a caller-specific optimization that leaked into a general-purpose function. The branch-pruner already independently checks against HEAD so this is safe. Co-authored-by: Copilot <[email protected]>
niik
approved these changes
May 11, 2026
niik
left a comment
Member
There was a problem hiding this comment.
Hi @KRRT7, thanks a bunch. This looks good, I've update this to parse the worktree output with null delimiters and a few other small changes but this is a solid improvement! I'm gonna approve but I imagine I'll have to get another one of my colleagues to do so as well given that I've contributed to the branch. We'll get this merged shortly
sergiou87
approved these changes
May 11, 2026
niik
enabled auto-merge
May 11, 2026 09:44
Contributor
Author
|
Thanks! |
8 tasks
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.
Summary
The
BranchPrunerdeletes local branches that are merged into the default branch and whose upstream remote branch no longer exists. It already skips reserved branches, the current HEAD, and recently checked out branches — but it has no awareness of git worktrees.A branch checked out in a linked worktree gets deleted, leaving that worktree in a broken state.
Changes
getWorktreeCheckedOutBranches()inapp/src/lib/git/worktree.ts— parsesgit worktree list --porcelainand returns the set of canonical refs checked out in linked worktreesapp/src/lib/git/index.tsBranchPruner.pruneLocalBranches()and exclude matched refs from the deletion setTest coverage
Coverage (Node built-in
--experimental-test-coverage):worktree.tsbranch-pruner.tsUncovered lines in
branch-pruner.tsare pre-existing (start()/stop()timer lifecycle, upstream ref edge cases) — not introduced by this change.Fixes
Fixes #8043