Repository navigation
fix(worktree): accurate merged detection and list without sizes - #524
Merged
Merged
Conversation
…erges BranchMerged used `git branch --merged`, which lists a branch with no commits of its own, so `flow wt prune --merged` removed worktrees that had just been created. It also never matched squash merges, and compared against a local default branch that is often never pulled. A branch now needs commits of its own (read from its reflog), and counts as merged when it is an ancestor of origin's default branch (local when there is no remote) or its combined change is patch-equivalent to a commit there.
Measuring disk usage walks every file in every worktree, including node_modules and build output, which makes list slow for callers that refresh it, such as a desktop panel.
Member
Author
|
Verification: |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
jahvon
marked this pull request as ready for review
November 19, 2026 21:46
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
Follow-up to #520.
flow wt prune --mergedcould delete a worktree created moments earlier, andwt listwas too slow for a caller that refreshes it (Mochi's desktop worktree panel).Notable Changes
BranchMergedusedgit branch --merged, which counts a branch with no commits of its own as merged, so a fresh worktree was flagged and pruned. A branch now needs commits of its own (from its reflog; without a reflog it falls back to the old check), and counts as merged when it is an ancestor of the default branch or its combined change is patch-equivalent to a commit there, which catches squash merges. It compares againstorigin/<default>when that exists, since a local default that is never pulled misses everything merged upstream.flow wt list --no-size: skips the per-worktree disk walk, which coversnode_modulesand build output and dominated the run time. MCPlist_worktreeskeeps sizes, since agents use them to pick cleanup targets.flowchart TD A[branch] --> B{own commits in reflog?} B -- no --> N[not merged] B -- yes --> C{ancestor of origin/default?} C -- yes --> M[merged] C -- no --> D{squashed tree patch-equivalent<br/>to a commit on default?} D -- yes --> M D -- no --> NNot changed:
wt addstill appends the worktree dir to.gitignorewithout saying so, andwt removestill falls back to a folder-name match. Both are worth a look but are outside this fix.