fix(server): scope gh's child git processes to the selected account - #9
Merged
Conversation
Per-project GitHub account pinning covered `git push`/`fetch` and the integrated terminal, but not the `git` processes `gh` itself spawns: `gh pr create` pushing a branch with no upstream, and `gh pr checkout` fetching, still fell back to the machine credential helper and acted as whichever account it had cached. `GitHubCli.execute` now passes the full auth env instead of the `gh`-only one. Also hardens the env itself: the `GIT_CONFIG_*` pairs are appended after any `GIT_CONFIG_COUNT` already in the parent environment, so an inherited runtime git config is no longer silently overwritten by our pairs claiming indices 0 and 1. A failed or empty `gh auth token` now logs a warning rather than falling back to the ambient account in silence. Adds the tests this path was missing (env shape, inherited-config offset, gh child-process env, terminal spawn env), fixes a `worktreeBranchPrefix` fixture that broke typecheck, and updates the docs note that still claimed plain git pushes were unscoped. Verified against two real gh accounts: with the pin, git authenticates as the selected account while a different one is globally active; without it, git resolves a stale OS keychain entry. Claude Opus 5 (1M context) via Claude Code
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.
Problem
Per-project GitHub account pinning (#7) covers
git push/fetchand the integrated terminal, but not thegitprocessesghitself spawns.GitHubCli.executepassedgitHubAccountGhEnv— token only, no credential config — so:gh pr createpushing a branch with no upstream, andgh pr checkoutfetchingstill fell back to the machine credential helper and acted as whichever account it had cached.
Fix
GitHubCli.executenow passesgitHubAccountAuthEnv, sogh's childgitprocesses inherit the same credential config as our own git calls.gitHubAccountAuthEnvappends itsGIT_CONFIG_*pairs after anyGIT_CONFIG_COUNTalready in the parent env. Previously it hardcodedCOUNT=2and claimed indices 0/1, silently discarding an inherited runtime git config.gh auth tokenwarns instead of quietly acting as the ambient account — that silence is what made the original bug hard to diagnose.GIT_CONFIG_COUNT,ghchild-process env, and terminal spawn env.GitHubAccountResolver.test.tswas missingworktreeBranchPrefixafter fix(server): restore access to existing worktrees #7 changed the contract, which broketsgo --noEmiton main. Fixed.source-control-providers.mdstill said plaingitpushes were unscoped. Replaced with what actually holds now, plus the two real limits (terminals pick up the account at spawn; SSH remotes can't be pinned).Verification
Against two real
ghaccounts on one machine:tsgo --noEmitclean, 259 tests pass acrosssourceControl/vcs/terminal, lint clean. Targeted checks only, per AGENTS.md — CI owns the full suite. Not exercised through the UI.🤖 Generated with Claude Code