Narrow git fetch origin to branch-specific fetches#642
Merged
Conversation
All six fetchOrigin call sites (createWorktree, getBranchStatus, getTaskDiff, mergeTask, checkMergedBranches, rebase script) only ever compare against origin/<baseBranch>. Pass that branch to fetchOrigin so the fetch is git fetch origin <branch> instead of a full-repo fetch. The fetch cache key changes from projectPath to projectPath:branch so different branches cache independently. pullOrigin's cache invalidation and removeFetchCache are updated accordingly. The fetchBranches (branch picker) path retains the full fetch since it populates a branch list and needs all remote refs.
rebaseTask: derive the fetch target from rebaseTarget (which may be a custom compareRef like origin/develop), not just baseBranch. getBranchStatusImpl / getTaskDiff: when params.compareRef points at a different origin branch, fetch that branch too so ahead/behind counts and diffs are computed against a fresh ref. checkMergedBranches: fetch every distinct baseBranch used by the task set, not only project.defaultBaseBranch, so per-task merge detection does not silently compare against a stale remote-tracking ref.
…queue Switching the dedup key from projectPath to projectPath:branch removed the implicit serializer that prevented concurrent git fetch processes for the same repo. Multiple parallel fetches (different branches) race on .git/packed-refs.lock on repos with packed refs (common on large repos where this optimization matters most). fetchProjectQueue chains each new fetch promise off the previous tail for that projectPath so at most one git fetch subprocess runs per repo at a time. Same-branch callers still coalesce via fetchInFlight before reaching the queue, so this only adds sequencing for different-branch concurrent fetches.
… clear getBranchStatusImpl: also fetch origin/<task-branch> (branchForPush) so getUnpushedCount sees out-of-band remote pushes to the task branch. The old full fetch refreshed this ref as a side effect; the narrowed fetch did not. _resetFetchState: add fetchProjectQueue.clear() to prevent cross-test isolation issues from stale queue tails (test-only helper).
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
git fetch origin(full fetch of all remote branches) withgit fetch origin <branch>in every call site that only needs the base branch ref. On repos with thousands of remote branches this makes each background fetch orders of magnitude faster.fetchProjectQueue) so concurrent branch-specific fetches for the same repo don't race on.git/packed-refs.lock.What changed
src/bun/git.tsfetchOrigin(projectPath, branch?)— new optionalbrancharg; runsgit fetch origin <branch>when providedprojectPathtoprojectPath:branch(orprojectPath:*for full fetch)fetchProjectQueueserializes concurrent git subprocesses per repo to avoid lock contentionremoveFetchCacheandpullOrigin's cache invalidation updated to match new key format_resetFetchStateclearsfetchProjectQueuefor test isolationsrc/bun/rpc-handlers/git-operations.ts— all narrowed call sites:createWorktree→ fetchesbaseBranchgetBranchStatusImpl→ fetchesbaseBranch+compareRefBranch(if different) +branchForPush(task branch, for unpushed count freshness)getTaskDiff→ fetchesbaseBranch+compareRefBranch(if different)mergeTask→ fetchesbaseBranchcheckMergedBranches→ fetches all distinct base branches across the task set (parallel, serialized by queue)git fetch origin <fetchBranch>derived from the actual rebase target refTest plan
git fetch originblockinggit fetch origin main(or your base branch), not a full fetch🤖 Generated with Claude Code