Repository navigation
fix(git): spawn git by its resolved path so macOS skips a PATH search per call - #869
Merged
jeff-r2026 merged 4 commits intoSep 28, 2026
Merged
Conversation
… per call On macOS, a bare-name spawn of git costs a few milliseconds for every PATH entry ahead of git's directory: 30-67 ms per call with a typical PATH, while git itself takes about 8 ms. createGit now passes simple-git the absolute path of the git that lookup would pick, resolved once per PATH value. Refs Tencent#868
A stat error other than ENOENT/ENOTDIR (a symlink loop) now keeps the bare name instead of moving on to a later git. Narrow the CHANGELOG to the simple-git paths and correct two comments. Refs Tencent#868
|
Findings
The PR description includes sufficient real-CLI/e2e testing evidence for the runtime change. |
A bare-name spawn moves past a PATH entry whose spawn fails, such as a script whose interpreter is gone, while a spawn by path just fails. gitBinary now spawns the candidate once (git --version) and keeps the bare name unless it starts. POSIX-only gitBinary cases skip on win32.
|
Findings
Resolved
|
…cutable A bare-name spawn walks PATH on every call, so a git removed or chmod'ed mid-process is skipped. gitBinary's cache kept the stale absolute path. One access(2) per call now drops a cached path that is no longer executable.
|
Findings
Resolved
|
jeff-r2026
approved these changes
Sep 28, 2026
5 of 9 tasks
Walternater
pushed a commit
to Walternater/teamai-cli
that referenced
this pull request
Nov 2, 2026
… per call (Tencent#869) * fix(git): spawn git by its resolved path so macOS skips a PATH search per call On macOS, a bare-name spawn of git costs a few milliseconds for every PATH entry ahead of git's directory: 30-67 ms per call with a typical PATH, while git itself takes about 8 ms. createGit now passes simple-git the absolute path of the git that lookup would pick, resolved once per PATH value. Refs Tencent#868 * fix(git): leave unreadable git candidates to the spawn's own lookup A stat error other than ENOENT/ENOTDIR (a symlink loop) now keeps the bare name instead of moving on to a later git. Narrow the CHANGELOG to the simple-git paths and correct two comments. Refs Tencent#868 * fix(git): keep the bare name when the first git on PATH does not start A bare-name spawn moves past a PATH entry whose spawn fails, such as a script whose interpreter is gone, while a spawn by path just fails. gitBinary now spawns the candidate once (git --version) and keeps the bare name unless it starts. POSIX-only gitBinary cases skip on win32. * fix(git): look PATH up again when the resolved git is gone or not executable A bare-name spawn walks PATH on every call, so a git removed or chmod'ed mid-process is skipped. gitBinary's cache kept the stale absolute path. One access(2) per call now drops a cached path that is no longer executable.
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
On macOS 26, looking up a bare-name
gitspawn costs a few milliseconds for every PATH entry ahead of git's directory. That is 30-67 ms per git call with an ordinary PATH, while git itself takes about 8 ms (#868).createGitnow gives simple-git the absolute path of thegitthat lookup would pick:export function createGit(basePath?: string): SimpleGit { if (basePath) { - return simpleGit({ baseDir: basePath }); + return simpleGit({ baseDir: basePath, binary: gitBinary() }); } - return simpleGit(); + return simpleGit({ binary: gitBinary() }); }gitBinary()(src/utils/git.ts) walks PATH the way a bare-name spawn does. It caches the result per PATH value and looks PATH up again when PATH changes, or when the cachedgitis gone or no longer executable (oneaccess(2)per call):The one
--versionspawn per PATH value is what makes the absolute path safe. A bare-name spawn moves past an entry whose spawn fails, such as a script whose interpreter is gone (ENOENT) or a file without execute permission, and a spawn by path does not. So the absolute path is used only when spawning it works, which is exactly the file the bare lookup would run. Whenever that does not hold, the bare name is kept, with today's lookup and today's errors.initReponow goes throughcreateGittoo. simple-git is built only in these two places, and every pull, push, reports and learnings operation goes through them, 18 to 70 git calls each.Left as they are: the direct
spawnSync/execFile('git', …)sites (provider clone,git --versionanduser.nameprobes,mr-hint,code-collector). Each runs once or a few times per command, and their tests assert that the spawned command isgit. The test fixtures' ownsimpleGit()calls are left too.Closes #868
Evidence
First
giton PATH does not start (review P1). Real CLI, isolatedHOME, a local bare git team repo,PATH=<dir with #!/nonexistent/sh git>:/opt/homebrew/bin:/usr/bin:/bin:<node>:✖ [user] Pull failed: Error: spawn /tmp/869-bench/broken/git ENOENT✔ [user] Team repo: already up to dateIn
git-binary.test.ts: an earliergitwith a missing interpreter plus real git later on PATH →gitBinaryreturnsgitandcreateGit(repo).init()succeeds. This fails at a4161ca and passes now. A resolvedgitremoved mid-process → the nextgitBinaryreturns the later one; one that loses execute permission →git(review P3). This fails at bf39067 and passes now.Speed, macOS 26 (Darwin 25.5), Node 22.23.3, measured at a4161ca with the same fixture (
teamai pullalready up to date). Seconds, 3 runs each. Before isorigin/main(5fb316c7):pullbeforepullafterpush --dry-runbeforepush --dry-runafternpxgives)npx vitest rungit-kind-reports.test.tsgit-kind-learnings.test.tslearnings-import-remnants.test.ts--maxWorkers=4macOS 27 (Darwin 27) does not show the lookup cost. #868's repro now gives 4.6 ms bare against 3.6 ms by path with 30 PATH entries, and 4.5 against 3.7 ms under
npm exec(38 entries). So at bf39067, before and after match within noise on Node 22, 24 and 26: an up-to-datepulltakes 0.6-0.9 s either way with a 54-entry PATH, andpush --dry-run0.15 s. The macOS 26 numbers above are from a4161ca. The--versionprobe adds one spawn per process (about 4 ms). Output is unchanged:✔ [user] Team repo: already up to date,ℹ No new or modified resources to push.Checks at the head commit:
npx vitest run --maxWorkers=4: 337 files, 5256 passed, 1 skipped.npx tsc --noEmitis clean.npm run lintreports 0 warnings. The e2e files that drive real git through the built CLI pass, 62 tests:self-mode-worktrees-808,deleted-worktree-scope-810,import-mr-publish-823,learnings-remnants-823,learnings-sync-704-705,reports-writer-sync-561,members-legacy-roster,init-unattended. The POSIX-onlygitBinarycases skip on win32, where there are no execute bits or shebangs (review P2).Linux CI is not expected to change much: a PATH miss there is a failed
execvpin the forked child, which is cheap.Merge Danger
Door: two-way. No state or config is written. Reverting restores the bare-name spawn.
Blast Radius: every simple-git call. Every case where the resolved path might not be the file the bare lookup would run falls back to the bare name, so the failure left is a
gitthat passes--versionand then behaves differently from the bare-name one, which is not expected.