perf(git): answer remote-URL questions from one subprocess, not one per remote (#18158)

Four copies of the same loop ran `git remote` and then a serial
`git remote get-url <name>` per remote to answer "which remote has this
URL". On a repo with 58 remotes that is 59 subprocesses -- measured at
1083 ms -- for one question, and worktree create asks it several times.
`git remote -v` answers for every remote from one child, reporting the
same insteadOf-expanded first fetch URL `get-url` prints.

The batched `cat-file --batch-check` branch-conflict probe decides from
stdout, but its WSL route was unfenced, so a login-shell fallback printed
the distro banner onto the stream it parses. That broke the
one-line-per-ref contract, made every batch undecided, and fell straight
back to one `show-ref` per remote -- the cost the batch exists to remove.

Measured at 58 remotes / 4346 branches, spawns and wall time:
  push-target remote scan      59 -> 1  (1083 ms -> 8 ms)
  branch-conflict probe        60 -> 3  (984 ms -> 43 ms)
  configured push target      123 -> 6  (2707 ms -> 157 ms)
This commit is contained in:
Neil
2026-09-02 12:53:48 -07:00
committed by GitHub
parent 1d94ebee3f
commit 104f9655e4
18 changed files with 841 additions and 128 deletions
@@ -15,6 +15,7 @@ import {
isUnsupportedWorktreeListZError
} from './git-worktree-command-capabilities'
import { gitCredentialPromptGuardEnv } from './git-credential-prompt-env'
import { parseGitRemoteFetchUrls } from './git-remote-url-index'
import { GIT_HISTORY_COMMIT_FORMAT, parseGitHistoryLog } from './git-history-log-parser'
import {
githubPullRequestHeadLocalRef,
@@ -214,6 +215,41 @@ describeBinaryCompatibility('real Git binary compatibility', () => {
await expect(runGit(['merge-base', '--end-of-options', head, unrelated])).rejects.toBeDefined()
})
// Why pin this: Orca answers "which remote has this URL" from one `git remote -v`
// instead of one `git remote get-url` per remote. That is only equivalent if both
// commands report the same URL — the insteadOf-expanded first `remote.<name>.url`,
// which a raw config read does not produce — on every supported Git.
it('reports the same fetch URL from remote -v as from remote get-url', async () => {
await runGit(['config', 'url.git@example.invalid:.insteadOf', 'https://example.invalid/'])
await runGit(['remote', 'add', 'compat-single', 'https://example.invalid/a/repo.git'])
await runGit(['remote', 'add', 'compat-multi', 'https://example.invalid/b/repo.git'])
await runGit([
'config',
'--add',
'remote.compat-multi.url',
'https://example.invalid/b2/repo.git'
])
await runGit([
'config',
'remote.compat-multi.pushurl',
'https://push.example.invalid/b/repo.git'
])
try {
const fetchUrls = parseGitRemoteFetchUrls((await runGit(['remote', '-v'])).stdout)
for (const name of ['compat-single', 'compat-multi']) {
const getUrl = (await runGit(['remote', 'get-url', name])).stdout.trim()
expect(fetchUrls.get(name)).toBe(getUrl)
}
expect(fetchUrls.get('compat-single')).toBe('git@example.invalid:a/repo.git')
// A `pushurl` must not displace the fetch URL the scan compares against.
expect(fetchUrls.get('compat-multi')).toBe('git@example.invalid:b/repo.git')
} finally {
await runGit(['remote', 'remove', 'compat-single'])
await runGit(['remote', 'remove', 'compat-multi'])
await runGit(['config', '--unset-all', 'url.git@example.invalid:.insteadOf'])
}
})
it('recognizes ref and merge-tree compatibility boundaries', async () => {
const fetchHeadPath = join(repoPath, '.git', 'FETCH_HEAD')
await writeFile(fetchHeadPath, 'sentinel\n')