refactor(repo): filter Branch::remotes() over the shared remote-branch inventory - #2371
Merged
Conversation
…h inventory Drops the per-call `git for-each-ref refs/remotes/*/<name>` subprocess in `Branch::remotes()` and replaces it with an in-memory filter over `Repository::remote_branches()`. The inventory was introduced in #2368; this is follow-up #1 — the one accessor left outside the consolidation. On `wt switch <branch>` for a remote-only branch, the old code spawned a duplicate `refs/remotes/` scan after the inventory scan had already run. After this change there is one canonical `for-each-ref refs/remotes/` per Repository, shared by every caller. Minor behavioral nuance: when multiple remotes have the same branch, `remotes()[0]` now reflects the inventory's committer-timestamp-desc order rather than git's alphabetical default. The only affected sites are informational (the remote name shown in a warning at `switch.rs:417` and the `RemoteOnlyBranch` error at `repository_ext.rs:156`) — no correctness impact, and nearly all users have a single remote. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
worktrunk-bot
approved these changes
Apr 22, 2026
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.
Drops the per-call
git for-each-ref refs/remotes/*/<name>subprocess inBranch::remotes()and replaces it with an in-memory filter overRepository::remote_branches(). The inventory was introduced in #2368; this is follow-up #1 — the one accessor left outside the consolidation.On
wt switch <branch>for a remote-only branch, the old code spawned a duplicaterefs/remotes/scan after the inventory scan had already run. After this change there is one canonicalfor-each-ref refs/remotes/per Repository, shared by every caller.Behavioral note
When multiple remotes have the same branch,
remotes()[0]now reflects the inventory's committer-timestamp-desc order rather than git's alphabetical default. The only affected sites are informational — the remote name shown in a warning atswitch.rs:417and theRemoteOnlyBrancherror atrepository_ext.rs:156. No correctness impact, and nearly all users have a single remote.