Skip to content

Make bb's git reads ignore user git display settings - #7785

Merged
ymichael merged 2 commits into
mainfrom
bb/make-git-machine-reads-ignore-user-git-settings-thr_9c4hyjtuus
Nov 18, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/make-git-machine-reads-ignore-user-git-settings-thr_9c4hyjtuus

Conversation

@ymichael

@ymichael ymichael commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

bb parses git output as if git ran with its defaults, but every git process inherited the user's git config and locale:

  • Display config changes the patch format. With color.ui=always, diff.mnemonicPrefix, diff.noprefix, diff.suppressBlankEmpty or diff.submodule=log|diff, the patches bb hands to the Diff panel either fail to parse or parse wrong. diff.relative drops changes outside the cwd when git runs from a subdirectory.
  • Translated git defeats English error matching. isMissingHeadRevisionError and similar matchers look for English stderr. Homebrew git with a non-English LANG answers in that language, so on a fresh git init repo the Diff shows a git error instead of the untracked files.
  • New worktrees stay racily clean. git worktree add writes the index in the same second as the last checked-out files. Nothing bb runs rewrites that index (status uses GIT_OPTIONAL_LOCKS=0), so every status re-hashes those files.

Found by auditing recent T3 Code fixes against bb: pingdotgg/t3code#29126 (colour), pingdotgg/t3code#28361 (diff.relative), pingdotgg/t3code#29579 (suppressBlankEmpty), pingdotgg/t3code#29852 (diff.submodule), pingdotgg/t3code#32252 (LANGUAGE=C) and pingdotgg/t3code#21341 (worktree index refresh).

What changed

  • packages/environment-provider-host/src/workspace-git.ts: resolveGitProcessEnv, which builds the environment for the shared runGit and for host-workspace's blob reads, now adds one set of command-scope config overrides through GIT_CONFIG_COUNT/KEY_n/VALUE_n: color.ui/color.diff/color.branch/color.status=never, diff.noprefix=false, diff.mnemonicPrefix=false, diff.srcPrefix=a/, diff.dstPrefix=b/, diff.suppressBlankEmpty=false, diff.relative=false, diff.submodule=short. Entries that are already present are kept, not overwritten: inherited ones (such as machine credential helpers) go first and caller-supplied ones (such as core.splitIndex=false) go last. Before this change a caller's GIT_CONFIG_* replaced the inherited entries.
  • The same function sets LANGUAGE=C unless the caller passes its own. gettext then prints English, and LANG/LC_* still reach hooks unchanged.
  • Every host-side git call bb parses goes through these two paths (git plugin reads, commit-cache patch-ids, environment providers, host-daemon branch/file reads, github-pr-status). I didn't change the remaining direct execFile("git") sites. They already set LC_ALL=C and read only output that doesn't depend on config: storage-retention worktree lists, host-watcher's status --porcelain -z, and the GitHub plugin's remote get-url.
  • plugins/environment-git-worktree/host/worktree.ts: worktree setup now runs git update-index -q --refresh --force-write-index before it hands the worktree out. If the rewritten index still falls in the checkout's second, it waits until 50 ms past that second and refreshes again. It skips that second pass if the wait would be 2 s or more (clock mismatch). Failures are ignored and cancellation still propagates.
  • Trade-offs:
    • Hooks run by bb-invoked git (commit, push, checkout) inherit these overrides, as they already did -c options. A hook that runs git diff sees standard, uncoloured output.
    • The second refresh can add up to about 1 s to worktree creation when the checkout and the first refresh end in the same second, which is the common case for small repos.
  • No daemon wire change, so HOST_DAEMON_PROTOCOL_VERSION is unchanged. No CLI or docs changes.

How you verified

Repro on origin/main (02264cf), real daemon: I ran a pnpm start:worktree instance with GIT_CONFIG_GLOBAL pointing at a scratch config and a Homebrew git 2.56.1 bottle (German catalog, LANG=de_DE.UTF-8) first on the daemon's PATH. I read bb git diff / bb git patch output and fed it to the app's own parser (parseGitDiffFiles from @bb/shared-ui):

global config origin/main this branch
none 4 files, blank.txt with 2 context lines same
color.ui=always 0 files (ANSI patch) 4 files
diff.mnemonicPrefix=true 4 files, name "" (invalid git diff header diff --git c/… w/…) names correct
diff.noprefix=true 4 files, name "" names correct
diff.suppressBlankEmpty=true blank.txt 1 context line (processFile: invalid rawLine) 2 context lines
diff.submodule=log 3 files, sub missing; patch sub → 0 files 4 files, sub present
German git, fresh git init repo Diff unavailable: git diff --no-ext-diff --binary HEAD failed: Schwerwiegend: mehrdeutiges Argument 'HEAD' … A hi.txt + patch

New worktree of a 40,000-file repo created by the same instance:

origin/main this branch
entries with mtime ≥ the index's second (racily clean) 730 0
git --no-optional-locks status median (9 runs) 0.170 s (0.118 s after a manual refresh) 0.120 s

The timings ran on a heavily loaded host and are only indicative. The racy-entry count is the deterministic signal.

Tests (each fails on origin/main, passes here):

  • workspace-git.test.ts › user Git settings on machine reads: a table with one repo per setting (color.ui, color.diff, diff.noprefix, diff.mnemonicPrefix, diff.srcPrefix/dstPrefix, diff.suppressBlankEmpty, diff.relative, diff.submodule=log, diff.submodule=diff). Each runs diff, log -p, show and a working-tree diff from a subdirectory and must match the unconfigured repo. The locale case uses a fake git that answers in German unless LANGUAGE=C, and asserts that LANG/LC_ALL pass through unchanged. A merge case checks that inherited and caller GIT_CONFIG_* entries survive alongside the overrides. On main: 11 failed. Here: 32/32.
  • environment-git-worktree/host.test.ts › writes a new worktree's index after its checkout second…. On main: expected 1795034299 to be greater than 1795034299. Here: 65/65.
  • pnpm exec turbo run typecheck lint for bb-environment-provider-host, bb-plugin-environment-git-worktree and @bb/host-workspace: pass.
  • pnpm exec turbo run test for bb-environment-provider-host, bb-plugin-environment-git-worktree, bb-plugin-bb--git, @bb/host-workspace, bb-plugin-bb--github-pr-status, bb-plugin-bb--storage-retention and @bb/host-daemon (894 passed): pass. Storage-retention timed out 3 tests in the parallel run under load and passed 103/103 alone. It doesn't use the changed code.

Not checked: Windows or Linux with a translated git. The locale test is skipped on Windows because its fake git is a shell script.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 2 commits November 18, 2026 12:45
Every git process bb spawns through the shared runGit now carries one
set of command-scope config overrides (no colour, a/ b/ prefixes,
suppressBlankEmpty and relative off, short submodule format), merged
with any GIT_CONFIG_* entries already present, plus LANGUAGE=C so
error matching sees English while hooks keep the user's LANG/LC_*.

New worktrees refresh their index after git worktree add, waiting into
the next second when needed, so status stops re-hashing racily clean
files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A second, delayed refresh only ran when checkout and the first refresh
finished within the same second, which happens only for small repos
whose racily clean entries cost almost nothing to re-hash. It added up
to about a second to worktree setup for no measurable status gain.

log.showSignature=true made every bb log/show verify commit signatures
and print the result into output bb parses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ymichael
ymichael merged commit b9cc4c6 into main Nov 18, 2026
49 checks passed
@ymichael
ymichael deleted the bb/make-git-machine-reads-ignore-user-git-settings-thr_9c4hyjtuus branch November 18, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant