Repository navigation
Read each git repo fact once per inspect call and check dirtiness with -unormal - #7100
Merged
ymichael merged 1 commit intoNov 5, 2026
Conversation
…h -unormal host.inspect_git_source and the project-checkout inspect/attach paths re-asked git whether the path is a repo, where its git dir and common dir are, and whether each default-branch ref exists before rev-parsing it again. One rev-parse now returns repo kind, git dir, common dir and linked-worktree state; it is passed down as a GitRepo. One for-each-ref reads origin/HEAD and the main/master refs with their oids. The dirty check uses --untracked-files=normal, since every caller only needs yes/no. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/follow-up-8-lighter-dirty-check-and-single-repo-thr_x5t864zbae
branch
November 5, 2026 17:54
ymichael
added a commit
that referenced
this pull request
Nov 5, 2026
…hRemoteBranches (#7132) ## What was wrong Main is red at 87a6e85. #7074 (b9ea287) and #7100 (87a6e85) merged minutes apart, and each passed CI on its own base: - #7074 added `getGitCommonDir` calls to `packages/environment-provider-host/src/branch-options.ts`. It also added the Git plugin's `fetchRemoteBranches` RPC, which calls `refreshRemoteBranches(path, …)`. - #7100 removed the `getGitCommonDir` import from `branch-options.ts` and changed `refreshRemoteBranches` to take a `GitRepo` instead of a path. On main this gives: - `Lint and typecheck`: `src/branch-options.ts(191,27): error TS2304: Cannot find name 'getGitCommonDir'`. - `ReferenceError: getGitCommonDir is not defined` in `packages-other`, `packages-host`, `plugins-2` and `integration` (Linux and Windows). Once the import is back, the Git plugin's `fetches remote branches when asked, never on a branch read` test still fails. The plugin passes a path string where `refreshRemoteBranches` now reads `repo.commonDir`, so no fetch ever starts. Opening a merge-base picker would not fetch remotes. ## Change - `branch-options.ts`: import `getGitCommonDir` again. - `plugins/git/host.ts`: `fetchRemoteBranches` resolves the repo with `readGitRepo` and skips non-repos, the same way the daemon's `host.inspect_git_source` caller does after #7100. It then calls `refreshRemoteBranches(repo, …)`. ## Verification Against origin/main 87a6e85 plus this change: - `turbo run typecheck` for `bb-environment-provider-host`, `bb-plugin-bb--git` and `@bb/host-daemon` passes. - `bb-environment-provider-host` tests: 48/48 pass, including `branch-options-cache.test.ts`, which failed on main. - `bb-plugin-bb--git` tests: 278/278 pass. `host.test.ts > fetches remote branches when asked` fails on main and fails with the import fix alone. It passes with this change, and also passed at b9ea287. - `@bb/host-daemon` `test/command/host-branches-dispatch.test.ts`: 21/21 pass. Several failed on main. - `tests/integration` `fake/smoke/environment-actions.test.ts`: 5/5 pass. It failed on main. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Human comments
What was wrong
This is the rest of finding #8 in the Nov 4 hot-path audit; #7067 did the first part. Two problems remained:
Dirty check lists every untracked file.
hasUncommittedChanges(packages/environment-provider-host/src/workspace-git.ts) rangit status --untracked-files=all, which lists every file inside untracked folders. Every caller only needs yes/no:host.inspect_git_source→hasUncommittedChanges: boolean→ the branch picker'sdirtyflaginspectCheckout→server.tsif (inspection.hasUncommittedChanges)assertSwitchableguard inattachCheckoutThe same repo questions are asked several times per call.
host.inspect_git_source(apps/host-daemon/src/command-handlers/host-branches.ts) asked:detectGitRepoKind, then again insidegetCheckoutRef,readDefaultBranchRefsandhasRef)--git-common-dir,--absolute-git-dirand--git-dironce each, as separate processesorigin/mainexist", then rev-parsedmainandorigin/mainagain for the relation checkThe project-checkout inspect and attach paths (
plugins/environment-project-checkout/host/checkout.ts) had the same pattern. On~/Projects/bbeach git process costs about 15 ms.What changed
--untracked-files=normalfor the status read (readPorcelainStatus). It gives the same yes/no: an untracked folder shows as onedir/entry, and empty or ignored-only folders are still hidden. The same read checks for conflicts during a rebase, merge, cherry-pick or revert. Conflicts only involve tracked files, so the untracked mode doesn't change that answer.readGitRepo(cwd)→GitRepo | null. It runs onerev-parse --is-inside-work-tree --is-bare-repository --git-dir --absolute-git-dir --git-common-dirand returns{ path, kind, gitDir, commonDir, isLinkedWorktree }:gitDirandcommonDirare resolved exactly asgetAbsoluteGitDirandgetGitCommonDirresolve them.isLinkedWorktreeuses the same--git-dir"/worktrees/" test as the olddetectLinkedWorktree, which this deletes along with its@bb/host-workspaceexport.detectGitRepoKindandensureGitReponow use it;ensureGitReporeturns theGitRepo.GitRepoinstead of re-detecting:readCheckoutRef(repo)(getCheckoutRef(cwd)keeps its detect-then-read behaviour)getWorkspaceGitOperation(repo)(usesrepo.gitDir)refreshRemoteBranches(repo, …)(usesrepo.commonDir)readDefaultBranchRefs(repo)readDefaultBranchRefsmakes onefor-each-refcall forrefs/remotes/origin/HEADplusrefs/heads|refs/remotes/origin×main|master, with their oids and symref. It replacessymbolic-ref+for-each-ref+hasRef(detect +show-ref) + 2 ×rev-parse. It queries more refs only when needed:symbolic-ref, so a dangling origin/HEAD still picks the same local branch as before (new test)inspect_git_sourceandinspect_git_checkouthandlerslistBranchOptionsinspectCheckoutandattachCheckout: they read the repo once;locateBranchis onefor-each-ref, and its result is passed fromplanSwitchtoassertSwitchableinstead of being looked up againresolveWorktreeBaseBranch:ensureGitRepothenreadDefaultBranchRefs, the same process count as beforeHOST_DAEMON_PROTOCOL_VERSIONbump.bb-environment-provider-hostis internal, so there is no plugin SDK change.How you verified
Benchmark on the real
~/Projects/bb(4,490 local branches, clean tree, git 2.50.1, onmain=origin/main):inspectHostGitSourcehandler and the project-checkout plugin'sinspectCheckoutandattachCheckout. TheattachCheckoutcall targets the branch already checked out, so it runs plan + assert and exits as already-current without switching.gitshim onPATH.origin/mainworktree outside this checkout) and the branch alternated for 6 rounds of 20 calls each. Each round started with a warm-up call and an 8 s wait so the background remote fetch wasn't counted.inspectHostGitSourcegit spawns/callinspectHostGitSourcep50 (median of rounds)inspectCheckoutgit spawns/callinspectCheckoutp50 (median of rounds)attachCheckout(no-op) git spawns/callattachCheckoutp50 (median of rounds)Git processes per
inspectHostGitSourcecall on the branch:rev-parse(repo facts)symbolic-ref HEADrev-parse --verify HEADfor-each-refstatus -unormalinspectCheckouttime doesn't change. Its two droppedrev-parsecalls ran in parallel withstatus(~80 ms), which still sets its wall time; the change saves process CPU there, not latency.-uallvs-unormal: the bb checkout was clean, so its numbers don't show the untracked-files saving. I measured it separately on a throwawayorigin/maincopy with 5,000 untracked files in 20 untracked folders, taking the median of 15 runs each:-uall: 72 ms, 5,000 output lines-unormal: 62 ms, 1 lineSame yes/no answer. The gap grows with untracked tree size.
Tests:
hasUncommittedChangeswith nested untracked folders vs empty or ignored-only folders.readDefaultBranchRefswith a dangling origin/HEAD.detectLinkedWorktreetest became areadGitRepotest covering a linked worktree, an ordinary checkout, a bare root and a plain folder.readDefaultBranchRefs,getCheckoutRef,getWorkspaceGitOperationand project-checkout attach tests pass.pnpm exec turbo run lint typecheck test --filter=bb-environment-provider-host --filter=@bb/host-workspace --filter=bb-plugin-environment-project-checkout --filter=bb-plugin-environment-git-worktree --filter=@bb/host-daemon --only: 12/12 tasks pass. CI runs the full suites.Left out:
tryWithCheckoutMutationLockstill runs its ownrev-parse --absolute-git-dir, soattachCheckoutmakes 7 git calls rather than 6. The lock reads the git dir inside its admission lock, and the worktree plugin's teardown also uses it. Passing a known git dir in would change the shared lock API for one process.readCheckoutRefstays 2 processes (symbolic-ref+rev-parse --verify HEAD, run in parallel). FoldingHEADinto the reporev-parsemakes the whole command fail in an unborn repo, so it would need a fallback path.hasRefcallers (worktreebase-branch.ts,worktree.ts) are not on the inspect/attach paths, so they're unchanged.fetchRemoteBranchesstill callsensureGitRepoonce per 30 s throttle window.🤖 Generated with Claude Code