Fix automatic branch rename for non-English git locales (#8012)

* Fix automatic branch rename for non-English git locales

A gettext-enabled git (Homebrew git, most Linux distro gits) under a
non-English locale translates every diagnostic, including the `fatal:`
prefix, so Orca's stderr phrase parsers stop matching. The first-message
branch auto-rename was the headline casualty: isNoUpstreamError missed
the translated no-upstream error, branchHasUpstream failed closed to
"has upstream", and the rename settled silently and permanently.

- Force LC_ALL=C on all Orca-spawned machine-parsed git: the local
  prompt-guard env chokepoint, the three relay git spawn sites, and both
  local clone spawns (progress + failure-message parsing). User
  terminals are untouched.
- Replace the boolean upstream check with a tri-state probe: rename
  proceeds only on a proven missing upstream; an unreadable probe now
  raises the rename-failed badge and retries instead of settling.

Fixes #7808

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>

* Consolidate untranslated-git-locale into runner and relay primitives

Replace the five per-site LC_ALL=C patches with one shared
UNTRANSLATED_GIT_OUTPUT_ENV (LANGUAGE=en LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8) injected inside the git runner primitives
(promptGuardGitEnv, gitSpawn, gitExecFileSync, gitExecFileAsyncBuffer)
and a relay buildRelayGitEnv() helper, so every current and future
machine-parsed git spawn is covered by construction — including the
fs-handler-git-fallback sites the per-site approach missed. The UTF-8
English locale keeps a UTF-8 LC_CTYPE for hooks git spawns; LANGUAGE is
pinned because gettext consults it before LC_ALL.

WSL-routed git gets the same values as a shell assignment prefix built
in resolveCommand, since spawn env cannot cross the wsl.exe boundary —
closing the WSL gap the first pass accepted.

Also scrub credential-bearing remote URLs from the probe-failed message
surfaced on the worktree card.

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>

* Scrub credential-bearing URLs from clone failure messages

---------

Co-authored-by: Brennan Benson <brennanbenson@Brennans-MacBook-Pro.local>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Brennan Benson
2026-07-10 01:03:16 -07:00
committed by GitHub
co-authored by Brennan Benson Claude
parent 6f895eff0a
commit b7e84aea3c
15 changed files with 260 additions and 53 deletions
@@ -373,6 +373,40 @@ describe('maybeAutoRenameBranchOnFirstWork', () => {
expect(onRenamed).not.toHaveBeenCalled()
})
it('surfaces a failed upstream probe and retries instead of settling silently (issue #7808)', async () => {
// Localized git (gettext + de_DE) translates even the `fatal:` prefix, so
// the no-upstream error is unrecognizable. This must not settle as "has
// upstream" — the badge goes up and a later event may still succeed.
const localizedError = new Error(
'Command failed: git rev-parse --abbrev-ref HEAD@{u}\n' +
"Schwerwiegend: Kein Upstream-Branch für Branch 'you/Nautilus' konfiguriert."
)
const plainResponder = gitResponder({ currentBranch: 'you/Nautilus', hasUpstream: false })
gitExecFileAsyncMock.mockImplementation(async (args: string[]) => {
if (args[0] === 'rev-parse' && args.some((arg) => arg.includes('@{u}'))) {
throw localizedError
}
return plainResponder(args)
})
const { deps, onRenamed, setRenameError } = makeDeps()
await maybeAutoRenameBranchOnFirstWork(workingEvent(), deps)
expect(generateBranchNameMock).not.toHaveBeenCalled()
expect(onRenamed).not.toHaveBeenCalled()
expect(setRenameError).toHaveBeenCalledWith(
WORKTREE_ID,
expect.stringContaining('Schwerwiegend')
)
// Once git output is readable again, the same worktree retries and renames.
gitExecFileAsyncMock.mockImplementation(plainResponder)
await maybeAutoRenameBranchOnFirstWork(workingEvent(), deps)
expect(gitExecFileAsyncMock).toHaveBeenCalledWith(
['branch', '-m', 'you/fix-auth'],
expect.objectContaining({ cwd: '/repo/wt' })
)
expect(setRenameError).toHaveBeenLastCalledWith(WORKTREE_ID, null)
})
it('leaves ineligible branches untouched even when their leaf is a creature name', async () => {
const { deps, onRenamed } = makeDeps({ canRenameOrcaCreatedBranch: () => false })
await maybeAutoRenameBranchOnFirstWork(workingEvent(), deps)
@@ -18,7 +18,7 @@ import { gitExecFileAsync } from '../git/runner'
import { getSshGitUsername, resolveLocalGitUsername } from '../git/git-username'
import { getSshGitProvider } from '../providers/ssh-git-dispatch'
import {
branchHasUpstream,
probeBranchUpstream,
renameCurrentBranch,
resolveUniqueBranchName,
type GitExec
@@ -207,9 +207,20 @@ async function runAutoRename(
return stop(`branch "${currentBranch}" is not an auto-generated name`, true)
}
// Never rewrite a branch that's already been published.
if (await branchHasUpstream(exec)) {
const upstreamProbe = await probeBranchUpstream(exec)
if (upstreamProbe.outcome === 'has-upstream') {
return stop(`branch "${currentBranch}" already has an upstream`, true)
}
if (upstreamProbe.outcome === 'probe-failed') {
// Why: settling an unreadable probe as "has upstream" made this failure
// silent and permanent via the settled cache (issue #7808).
const probeError = upstreamProbe.message.replace(/\s+/g, ' ').trim()
deps.setRenameError(
worktreeId,
`Could not check whether the branch is published: ${probeError}`
)
return retry(`upstream probe failed: ${probeError}`)
}
const settings = deps.getSettings()
const hostKey = getCommitMessageModelDiscoveryHostKey(repo.connectionId ?? null)
@@ -249,8 +260,13 @@ async function runAutoRename(
if (branchNow !== currentBranch) {
return retry(`branch changed during generation (${currentBranch} -> ${branchNow})`)
}
if (await branchHasUpstream(exec)) {
return retry(`branch "${currentBranch}" was pushed during generation`)
const postGenerationProbe = await probeBranchUpstream(exec)
if (postGenerationProbe.outcome !== 'no-upstream') {
return retry(
postGenerationProbe.outcome === 'has-upstream'
? `branch "${currentBranch}" was pushed during generation`
: `upstream probe failed after generation: ${postGenerationProbe.message}`
)
}
const username = provider
+42 -10
View File
@@ -1,6 +1,6 @@
import { describe, expect, it, vi } from 'vitest'
import {
branchHasUpstream,
probeBranchUpstream,
renameCurrentBranch,
resolveUniqueBranchName,
type GitExec
@@ -12,8 +12,8 @@ const noUpstreamError = new Error(
' git push --set-upstream origin feature'
)
describe('branchHasUpstream', () => {
it('is true when @{u} resolves to a tracking ref', async () => {
describe('probeBranchUpstream', () => {
it('reports has-upstream when @{u} resolves to a tracking ref', async () => {
const exec: GitExec = vi.fn(async (args: string[]) => {
if (args[0] === 'symbolic-ref') {
return { stdout: 'feature\n', stderr: '' }
@@ -23,10 +23,10 @@ describe('branchHasUpstream', () => {
}
throw new Error(`unexpected git args: ${args.join(' ')}`)
})
expect(await branchHasUpstream(exec)).toBe(true)
expect(await probeBranchUpstream(exec)).toEqual({ outcome: 'has-upstream' })
})
it('is false when there is no upstream', async () => {
it('reports no-upstream when there is no upstream', async () => {
const exec: GitExec = vi.fn(async (args: string[]) => {
if (args[0] === 'symbolic-ref') {
return { stdout: 'feature\n', stderr: '' }
@@ -39,10 +39,10 @@ describe('branchHasUpstream', () => {
}
throw new Error(`unexpected git args: ${args.join(' ')}`)
})
expect(await branchHasUpstream(exec)).toBe(false)
expect(await probeBranchUpstream(exec)).toEqual({ outcome: 'no-upstream' })
})
it('is true when a same-name origin tracking ref exists without configured upstream', async () => {
it('reports has-upstream when a same-name origin tracking ref exists without configured upstream', async () => {
const exec: GitExec = vi.fn(async (args: string[]) => {
if (args[0] === 'symbolic-ref') {
return { stdout: 'feature\n', stderr: '' }
@@ -55,12 +55,44 @@ describe('branchHasUpstream', () => {
}
throw new Error(`unexpected git args: ${args.join(' ')}`)
})
expect(await branchHasUpstream(exec)).toBe(true)
expect(await probeBranchUpstream(exec)).toEqual({ outcome: 'has-upstream' })
})
it('is conservatively true on an unexpected failure', async () => {
it('reports probe-failed on an unexpected failure', async () => {
const exec: GitExec = vi.fn().mockRejectedValue(new Error('fatal: not a git repository'))
expect(await branchHasUpstream(exec)).toBe(true)
expect(await probeBranchUpstream(exec)).toEqual({
outcome: 'probe-failed',
message: 'fatal: not a git repository'
})
})
it('scrubs credential-bearing URLs from the probe-failed message', async () => {
// The message surfaces on the worktree card, so an embedded remote URL
// must not leak a token or password into the UI.
const exec: GitExec = vi
.fn()
.mockRejectedValue(
new Error('fatal: unable to access https://user:hunter2@example.com/repo.git/: timed out')
)
expect(await probeBranchUpstream(exec)).toEqual({
outcome: 'probe-failed',
message: 'fatal: unable to access https://example.com/repo.git/: timed out'
})
})
it('reports probe-failed, not has-upstream, for localized git diagnostics (issue #7808)', async () => {
// A gettext-enabled git under de_DE translates even the `fatal:` prefix.
const exec: GitExec = vi.fn(async (args: string[]) => {
if (args[0] === 'symbolic-ref') {
return { stdout: 'feature\n', stderr: '' }
}
throw new Error(
'Command failed: git rev-parse --abbrev-ref HEAD@{u}\n' +
"Schwerwiegend: Kein Upstream-Branch für Branch 'feature' konfiguriert."
)
})
const probe = await probeBranchUpstream(exec)
expect(probe.outcome).toBe('probe-failed')
})
})
+20 -11
View File
@@ -1,4 +1,4 @@
import { isNoUpstreamError } from '../../shared/git-remote-error'
import { isNoUpstreamError, stripCredentialsFromMessage } from '../../shared/git-remote-error'
import {
resolveEffectiveGitUpstream,
type GitCommandRunner
@@ -11,22 +11,31 @@ import {
*/
export type GitExec = GitCommandRunner
export type BranchUpstreamProbe =
| { outcome: 'has-upstream' }
| { outcome: 'no-upstream' }
| { outcome: 'probe-failed'; message: string }
/**
* True when the branch has a configured upstream — i.e. it has been pushed or
* is tracking a remote. Auto-rename refuses to touch such a branch because
* `git branch -m` would orphan the remote branch and break any open PR.
* Whether the branch has an upstream — i.e. it has been pushed or is tracking
* a remote. Auto-rename refuses to touch such a branch because `git branch -m`
* would orphan the remote branch and break any open PR.
*/
export async function branchHasUpstream(exec: GitExec): Promise<boolean> {
export async function probeBranchUpstream(exec: GitExec): Promise<BranchUpstreamProbe> {
try {
return (await resolveEffectiveGitUpstream(exec)) !== null
const upstream = await resolveEffectiveGitUpstream(exec)
return { outcome: upstream !== null ? 'has-upstream' : 'no-upstream' }
} catch (error) {
if (isNoUpstreamError(error)) {
return false
return { outcome: 'no-upstream' }
}
// Why: an unexpected failure is not proof either way — report it as its own
// outcome so callers skip the rename but stay retryable (issue #7808).
// The message surfaces in the UI, so scrub credential-bearing remote URLs.
return {
outcome: 'probe-failed',
message: stripCredentialsFromMessage(error instanceof Error ? error.message : String(error))
}
// Why: an unexpected failure (detached HEAD, corruption, transport error)
// is not proof there's no upstream. Stay conservative and report "has
// upstream" so the caller skips the rename rather than risk a published branch.
return true
}
}
+24 -1
View File
@@ -9,7 +9,8 @@ import {
nonInteractiveGitEnv,
parseRetryAfterMs,
promptGuardGitEnv,
redirectPortedHostnameToEnv
redirectPortedHostnameToEnv,
untranslatedGitOutputEnv
} from './runner'
// Reads git config injected via the GIT_CONFIG_COUNT/KEY/VALUE env protocol
@@ -218,3 +219,25 @@ describe('nonInteractiveGitEnv credential-interactivity disable (STA-1292)', ()
expect(env.GIT_SSH_COMMAND).toBe('ssh -o BatchMode=yes')
})
})
describe('git env forces untranslated diagnostics (issue #7808)', () => {
it('overrides an inherited non-English locale so stderr parsers keep working', () => {
// A gettext-enabled git under de_DE translates even the `fatal:` prefix,
// breaking isNoUpstreamError and every other stderr phrase match.
const env = promptGuardGitEnv({ PATH: '/usr/bin', LC_ALL: 'de_DE.UTF-8' })
expect(env.LC_ALL).toBe('en_US.UTF-8')
expect(env.LANG).toBe('en_US.UTF-8')
})
it('pins LANGUAGE, which outranks LC_ALL in gettext lookups', () => {
const env = untranslatedGitOutputEnv({ PATH: '/usr/bin', LANGUAGE: 'de:en' })
expect(env.LANGUAGE).toBe('en')
expect(env.LC_ALL).toBe('en_US.UTF-8')
})
it('applies to nonInteractiveGitEnv as well', () => {
const env = nonInteractiveGitEnv({ PATH: '/usr/bin', LANG: 'fr_FR.UTF-8' })
expect(env.LC_ALL).toBe('en_US.UTF-8')
expect(env.LANGUAGE).toBe('en')
})
})
+30 -4
View File
@@ -35,9 +35,17 @@ import {
escapeWslShCommandForWindows,
quotePosixShell
} from '../../shared/wsl-login-shell-command'
import { UNTRANSLATED_GIT_OUTPUT_ENV } from '../../shared/git-output-locale'
// ─── Core resolution ────────────────────────────────────────────────
// `LANGUAGE=en LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8` — env-assignment prefix for
// WSL-routed git, where spawn env cannot cross the wsl.exe boundary. Values are
// shell-safe unquoted (alnum, dot, dash, underscore only).
const GIT_OUTPUT_LOCALE_SHELL_PREFIX = Object.entries(UNTRANSLATED_GIT_OUTPUT_ENV)
.map(([key, value]) => `${key}=${value}`)
.join(' ')
type ResolvedCommand = {
binary: string
args: string[]
@@ -202,6 +210,10 @@ function resolveCommand(
}
const translatedArgs = translateArgsForWsl(args)
// Why: env set on wsl.exe stays on the Windows side (WSLENV forwards only
// named vars), so the untranslated-output locale must ride the command
// string for git stderr parsers to work inside the distro (issue #7808).
const localePrefix = command === 'git' ? `${GIT_OUTPUT_LOCALE_SHELL_PREFIX} ` : ''
const escapedCommand = quotePosixShell(command)
// Why: shell-escape each argument to prevent word splitting / glob expansion
// inside the bash -c string. Single quotes are safe for all chars except
@@ -214,8 +226,8 @@ function resolveCommand(
// doesn't need a particular cwd for global calls like `api rate_limit`.
const linuxCwd = cwdWsl?.linuxPath ?? (cwd && wslDistroOverride ? translateArgForWsl(cwd) : null)
const shellCmd = linuxCwd
? `cd ${quotePosixShell(linuxCwd)} && ${escapedCommand} ${escapedArgs.join(' ')}`
: `${escapedCommand} ${escapedArgs.join(' ')}`
? `cd ${quotePosixShell(linuxCwd)} && ${localePrefix}${escapedCommand} ${escapedArgs.join(' ')}`
: `${localePrefix}${escapedCommand} ${escapedArgs.join(' ')}`
if (options.useWslLoginShell) {
return {
@@ -560,10 +572,21 @@ export function appendGitConfigEnv(
return next
}
/**
* Pin Orca-spawned git to untranslated English output so stderr/progress
* parsers keep working under any user locale (issue #7808; see
* UNTRANSLATED_GIT_OUTPUT_ENV for the full rationale). Terminal git is
* untouched. Injected by every git runner in this module; WSL-routed spawns
* get the same values via GIT_OUTPUT_LOCALE_SHELL_PREFIX instead.
*/
export function untranslatedGitOutputEnv(env: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
return { ...env, ...UNTRANSLATED_GIT_OUTPUT_ENV }
}
export function promptGuardGitEnv(env: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
return appendGitConfigEnv(
{
...env,
...untranslatedGitOutputEnv(env),
GIT_TERMINAL_PROMPT: '0',
GIT_ASKPASS: env.GIT_ASKPASS ?? '',
SSH_ASKPASS: env.SSH_ASKPASS ?? '',
@@ -870,7 +893,8 @@ export async function gitExecFileAsyncBuffer(
const { stdout } = (await execFileCapture(resolved.binary, resolved.args, {
cwd: resolved.cwd,
encoding: 'buffer',
maxBuffer: options.maxBuffer
maxBuffer: options.maxBuffer,
env: untranslatedGitOutputEnv()
})) as { stdout: Buffer }
return { stdout }
}
@@ -1051,6 +1075,7 @@ export function gitExecFileSync(
return execFileSync(resolved.binary, resolved.args, {
cwd: resolved.cwd,
encoding: options.encoding ?? 'utf-8',
env: untranslatedGitOutputEnv(),
stdio: options.stdio ?? ['pipe', 'pipe', 'pipe'],
timeout: options.timeout ?? GIT_EXEC_SYNC_TIMEOUT_MS
}) as string
@@ -1076,6 +1101,7 @@ export function gitSpawn(
const spawnStartedAt = performance.now()
const child = spawn(resolved.binary, resolved.args, {
...spawnOptions,
env: untranslatedGitOutputEnv(spawnOptions.env ?? process.env),
cwd: resolved.cwd
})
recordSubprocessSpawn(resolved.binary, resolved.args, performance.now() - spawnStartedAt)
+11 -11
View File
@@ -5452,7 +5452,7 @@ describe('OrcaRuntimeService', () => {
it('keeps project clone setup on the cloned host-qualified repo', async () => {
const destination = await mkdtemp(join(tmpdir(), 'orca-runtime-project-clone-'))
const clonePath = join(destination, 'orca')
const spawnSpy = vi.spyOn(gitRunner, 'wslAwareSpawn')
const spawnSpy = vi.spyOn(gitRunner, 'gitSpawn')
const repos: Record<string, unknown>[] = []
getRepoUpstreamMock.mockResolvedValue({ owner: 'stablyai', repo: 'orca' })
const runtimeStore = {
@@ -5514,7 +5514,7 @@ describe('OrcaRuntimeService', () => {
it('adopts public clone repos into host-qualified project setup', async () => {
const destination = await mkdtemp(join(tmpdir(), 'orca-runtime-project-clone-'))
const clonePath = join(destination, 'orca')
const spawnSpy = vi.spyOn(gitRunner, 'wslAwareSpawn')
const spawnSpy = vi.spyOn(gitRunner, 'gitSpawn')
const repos: Record<string, unknown>[] = []
getRepoUpstreamMock.mockResolvedValue({ owner: 'stablyai', repo: 'orca' })
const runtimeStore = {
@@ -5584,7 +5584,7 @@ describe('OrcaRuntimeService', () => {
it('keeps project clone repos split by runtime host on the same clone path', async () => {
const destination = await mkdtemp(join(tmpdir(), 'orca-runtime-project-clone-'))
const clonePath = join(destination, 'orca')
const spawnSpy = vi.spyOn(gitRunner, 'wslAwareSpawn')
const spawnSpy = vi.spyOn(gitRunner, 'gitSpawn')
const repos: Record<string, unknown>[] = [
{
id: 'repo-host-a',
@@ -5755,7 +5755,7 @@ describe('OrcaRuntimeService', () => {
})
it('defaults runtime cloneRepo badgeColor to DEFAULT_REPO_BADGE_COLOR', async () => {
const spawnSpy = vi.spyOn(gitRunner, 'wslAwareSpawn')
const spawnSpy = vi.spyOn(gitRunner, 'gitSpawn')
const added: Record<string, unknown>[] = []
const colorStore = {
...store,
@@ -5791,7 +5791,7 @@ describe('OrcaRuntimeService', () => {
})
it('preserves existing badgeColor on runtime cloneRepo folder->git dedupe upgrade', async () => {
const spawnSpy = vi.spyOn(gitRunner, 'wslAwareSpawn')
const spawnSpy = vi.spyOn(gitRunner, 'gitSpawn')
spawnSpy.mockImplementation(() => {
const proc = new EventEmitter() as EventEmitter & { stderr: EventEmitter }
proc.stderr = new EventEmitter()
@@ -5889,7 +5889,7 @@ describe('OrcaRuntimeService', () => {
})
it('rejects runtime cloneRepo dot-segment URLs before spawning git', async () => {
const spawnSpy = vi.spyOn(gitRunner, 'wslAwareSpawn')
const spawnSpy = vi.spyOn(gitRunner, 'gitSpawn')
const runtime = createRuntime()
const tempRoot = await mkdtemp(join(tmpdir(), 'orca-runtime-clone-'))
const destination = join(tempRoot, 'destination')
@@ -5906,7 +5906,7 @@ describe('OrcaRuntimeService', () => {
})
it('rejects runtime cloneRepo parent-segment URLs before spawning git', async () => {
const spawnSpy = vi.spyOn(gitRunner, 'wslAwareSpawn')
const spawnSpy = vi.spyOn(gitRunner, 'gitSpawn')
const runtime = createRuntime()
const tempRoot = await mkdtemp(join(tmpdir(), 'orca-runtime-clone-'))
const destination = join(tempRoot, 'destination')
@@ -5923,7 +5923,7 @@ describe('OrcaRuntimeService', () => {
})
it('removes an owned runtime clone target when git exits unsuccessfully', async () => {
const spawnSpy = vi.spyOn(gitRunner, 'wslAwareSpawn')
const spawnSpy = vi.spyOn(gitRunner, 'gitSpawn')
const proc = new EventEmitter() as EventEmitter & { stderr: EventEmitter }
proc.stderr = new EventEmitter()
spawnSpy.mockReturnValue(proc as never)
@@ -5950,7 +5950,7 @@ describe('OrcaRuntimeService', () => {
})
it('preserves an existing runtime clone target when git exits unsuccessfully', async () => {
const spawnSpy = vi.spyOn(gitRunner, 'wslAwareSpawn')
const spawnSpy = vi.spyOn(gitRunner, 'gitSpawn')
const proc = new EventEmitter() as EventEmitter & { stderr: EventEmitter }
proc.stderr = new EventEmitter()
spawnSpy.mockReturnValue(proc as never)
@@ -5977,7 +5977,7 @@ describe('OrcaRuntimeService', () => {
})
it('skips runtime clone failure cleanup when the owned target is replaced', async () => {
const spawnSpy = vi.spyOn(gitRunner, 'wslAwareSpawn')
const spawnSpy = vi.spyOn(gitRunner, 'gitSpawn')
const proc = new EventEmitter() as EventEmitter & { stderr: EventEmitter }
proc.stderr = new EventEmitter()
spawnSpy.mockReturnValue(proc as never)
@@ -6006,7 +6006,7 @@ describe('OrcaRuntimeService', () => {
})
it('serializes concurrent runtime clones for the same target', async () => {
const spawnSpy = vi.spyOn(gitRunner, 'wslAwareSpawn')
const spawnSpy = vi.spyOn(gitRunner, 'gitSpawn')
const firstProc = new EventEmitter() as EventEmitter & { stderr: EventEmitter }
firstProc.stderr = new EventEmitter()
spawnSpy.mockReturnValueOnce(firstProc as never)
+3 -3
View File
@@ -41,7 +41,7 @@ import {
AGENT_PROMPT_SUBMIT_DELAY_MS,
buildAgentPromptPasteBytes
} from '../../shared/agent-prompt-injection'
import { gitExecFileAsync, wslAwareSpawn } from '../git/runner'
import { gitExecFileAsync, gitSpawn } from '../git/runner'
import {
cleanupClaimedCloneTarget,
claimCloneTarget,
@@ -10692,9 +10692,9 @@ export class OrcaRuntimeService {
await mkdir(trimmedDestination, { recursive: true })
const claimedTarget = await claimCloneTarget(clonePath)
await new Promise<void>((resolve, reject) => {
let proc: ReturnType<typeof wslAwareSpawn>
let proc: ReturnType<typeof gitSpawn>
try {
proc = wslAwareSpawn('git', ['clone', '--progress', '--', trimmedUrl, clonePath], {
proc = gitSpawn(['clone', '--progress', '--', trimmedUrl, clonePath], {
cwd: trimmedDestination,
stdio: ['ignore', 'ignore', 'pipe']
})
+3 -3
View File
@@ -19,7 +19,7 @@ import {
ingestGitGrepLine,
SEARCH_TIMEOUT_MS
} from '../shared/text-search'
import { buildRelayCommandEnv } from './relay-command-env'
import { buildRelayGitEnv } from './relay-command-env'
/**
* List files using `git ls-files`. Fallback when rg is not installed.
@@ -61,7 +61,7 @@ export function listFilesWithGit(
const child = spawn('git', ['ls-files', ...args], {
cwd: rootPath,
env: buildRelayCommandEnv(),
env: buildRelayGitEnv(),
stdio: ['ignore', 'pipe', 'pipe']
})
let timer: ReturnType<typeof setTimeout> | null = null
@@ -209,7 +209,7 @@ export function searchWithGitGrep(
const child = spawn('git', gitArgs, {
cwd: rootPath,
env: buildRelayCommandEnv(),
env: buildRelayGitEnv(),
stdio: ['ignore', 'pipe', 'pipe']
})
let killTimeout: ReturnType<typeof setTimeout>
+4 -4
View File
@@ -52,7 +52,7 @@ import {
resolveEffectiveGitUpstream
} from '../shared/git-effective-upstream'
import { loadGitHistoryFromExecutor } from '../shared/git-history'
import { buildRelayCommandEnv } from './relay-command-env'
import { buildRelayGitEnv } from './relay-command-env'
import {
removeSafeUntrackedDiscardTarget,
removeSafeUntrackedDiscardTargets
@@ -254,7 +254,7 @@ export class GitHandler {
stdin?: string
}
): Promise<{ stdout: string; stderr: string }> {
const env = buildRelayCommandEnv()
const env = buildRelayGitEnv()
if (opts?.disableOptionalLocks) {
env.GIT_OPTIONAL_LOCKS = '0'
}
@@ -281,7 +281,7 @@ export class GitHandler {
private async gitBuffer(args: string[], cwd: string): Promise<Buffer> {
const { stdout } = (await execFileAsync('git', args, {
cwd,
env: buildRelayCommandEnv(),
env: buildRelayGitEnv(),
encoding: 'buffer',
maxBuffer: MAX_GIT_BUFFER
})) as { stdout: Buffer }
@@ -1097,7 +1097,7 @@ export class GitHandler {
return await new Promise((resolve, reject) => {
const child = spawn('git', args, {
cwd: expandTilde(cwd),
env: buildRelayCommandEnv(),
env: buildRelayGitEnv(),
stdio: ['ignore', 'pipe', 'pipe']
})
let stdout = ''
+18 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, it, vi } from 'vitest'
import { homedir } from 'node:os'
import { buildRelayCommandEnv } from './relay-command-env'
import { buildRelayCommandEnv, buildRelayGitEnv } from './relay-command-env'
// homedir() is the fallback when the relay env carries no HOME; mock it so the
// fallback path is deterministic and the "no resolvable home" branch is reachable.
@@ -228,3 +228,20 @@ describe('buildRelayCommandEnv', () => {
expect(env.PATH?.split(':')).toContain('/home/fallback/.local/bin')
})
})
describe('buildRelayGitEnv', () => {
it('pins an untranslated locale on top of the command env (issue #7808)', () => {
// Relay git stderr/progress is machine-parsed; a non-English host locale
// with a gettext git would translate it and break the parsers.
const env = buildRelayGitEnv(
{ HOME: '/home/me', PATH: '/usr/bin', LC_ALL: 'de_DE.UTF-8' },
'linux'
)
expect(env.LC_ALL).toBe('en_US.UTF-8')
expect(env.LANG).toBe('en_US.UTF-8')
expect(env.LANGUAGE).toBe('en')
// PATH fallback behavior is unchanged.
expect(env.PATH?.split(':')).toEqual(expect.arrayContaining(['/usr/bin', '/usr/local/bin']))
})
})
+14
View File
@@ -1,5 +1,6 @@
import { homedir } from 'node:os'
import { posix, win32 } from 'node:path'
import { UNTRANSLATED_GIT_OUTPUT_ENV } from '../shared/git-output-locale'
const POSIX_RELAY_PATH_FALLBACKS = ['/usr/local/bin', '/opt/homebrew/bin', '/usr/bin', '/bin']
const WINDOWS_RELAY_PATH_FALLBACKS = [
@@ -154,3 +155,16 @@ export function buildRelayCommandEnv(
[key]: [...segments].join(delimiter)
}
}
/**
* Env for relay-spawned git specifically: the PATH fallbacks above plus a
* pinned English UTF-8 locale, because relay git output is machine-parsed
* (stderr phrase matching, progress regexes) and a gettext-enabled git under
* a non-English host locale translates it (issue #7808).
*/
export function buildRelayGitEnv(
baseEnv: NodeJS.ProcessEnv = process.env,
platform: NodeJS.Platform = process.platform
): NodeJS.ProcessEnv {
return { ...buildRelayCommandEnv(baseEnv, platform), ...UNTRANSLATED_GIT_OUTPUT_ENV }
}
@@ -46,6 +46,18 @@ describe('getGitCloneFailureMessage', () => {
)
})
it('scrubs credential-bearing clone URLs before surfacing the fatal line', () => {
// Clone errors echo the URL the user typed — the most likely git error to
// embed a live token — and the message reaches dialogs and bug reports.
const stderr =
'Cloning into repo...\n' +
"fatal: repository 'https://user:ghp_secret123@github.com/org/repo.git/' not found\n"
expect(getGitCloneFailureMessage(stderr)).toBe(
"fatal: repository 'https://github.com/org/repo.git/' not found"
)
})
it('summarizes CRLF-heavy stderr without line-array splitting', () => {
const splitSpy = vi.spyOn(String.prototype, 'split')
const stderr = `${'remote: counting objects\r\n'.repeat(10_000)}fatal: repository not found\r\n`
+9 -1
View File
@@ -1,10 +1,18 @@
import { stripCredentialsFromMessage } from './git-remote-error'
export function getGitCloneFailureMessage(
stderr: string,
options: { clonePath?: string | null } = {}
): string {
let fallbackLine: string | null = null
for (const rawLine of iterateLinesFromEnd(stderr)) {
// Why: clone errors echo the URL the user typed, which is the most likely
// git error to embed a live token (`https://user:ghp_…@host/repo.git`).
// Scrub up-front so every return branch operates on already-redacted text,
// matching normalizeGitErrorMessage.
const scrubbedStderr = stripCredentialsFromMessage(stderr)
for (const rawLine of iterateLinesFromEnd(scrubbedStderr)) {
const line = stripAnsi(rawLine).trim()
if (!line) {
continue
+16
View File
@@ -0,0 +1,16 @@
/**
* Env pinning git subprocess output to untranslated English (issue #7808).
*
* Why: Orca parses git's stderr diagnostics and progress lines (e.g.
* isNoUpstreamError, clone progress/`fatal:` matching); a gettext-enabled git
* under a non-English locale translates even the `fatal:` prefix and silently
* breaks those parsers. An English UTF-8 locale rather than plain `C` keeps a
* UTF-8 LC_CTYPE for hooks git spawns (commit, push); a host without
* en_US.UTF-8 falls back to C, which still emits untranslated messages.
* LANGUAGE outranks LC_ALL in gettext's lookup, so it is pinned too.
*/
export const UNTRANSLATED_GIT_OUTPUT_ENV = {
LANGUAGE: 'en',
LC_ALL: 'en_US.UTF-8',
LANG: 'en_US.UTF-8'
} as const