Files
orca/src/shared/git-command-failure-text.ts
T
Neil 328caa2160 fix(git): reduce queries and preserve data across execution hosts (#24602)
* fix(git): reduce queries and preserve data across execution hosts

* fix(ci): exercise pinned Git and serialize mobile dependency entrypoints

* fix(relay): preserve fresh diff retries after hung shared reads

* test(git): wait for fetch barrier before canceling preparation

* fix(i18n): describe index-preserving discard in every locale

* fix(git): retain clone diagnostics and allow WSL policy startup

* test(git): refresh default-base and branch-safety fixtures
2026-10-02 18:05:37 -07:00

41 lines
1.6 KiB
TypeScript

/**
* The text a failed Git invocation left behind, for the predicates that classify a
* failure by what Git said.
*
* Why all three streams and not just `message` + `stderr`: the errors Orca classifies
* do not all come straight out of `execFile`. Node puts Git's stderr in both `message`
* and `stderr`, but Orca also throws its own failures with the Git output on `stdout`
* (`worktree remove`'s submodule retry attaches `git status --porcelain` output that
* way on both the local runner and the relay). Reading all three is what keeps the
* local and relay classifiers from disagreeing about the same error object.
*
* Against a real binary this reads no differently: Git emits every refusal this module
* classifies through `error()`/`die()`, i.e. stderr only, on 2.25 through 2.55.
*/
export function readGitCommandFailureText(error: unknown): string {
if (typeof error !== 'object' || error === null) {
return String(error)
}
const parts: string[] = []
for (const field of ['message', 'stderr', 'stdout'] as const) {
const value = (error as Record<string, unknown>)[field]
if (typeof value === 'string' && value) {
parts.push(value)
}
}
return parts.join('\n')
}
export function readGitCommandFailureStderr(error: unknown): string | null {
if (typeof error !== 'object' || error === null || !('stderr' in error)) {
return null
}
if (typeof error.stderr === 'string') {
return error.stderr
}
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(error.stderr)) {
return error.stderr.toString('utf8')
}
return null
}