@@ -6,15 +6,20 @@ import type { DiffFile, DiffHunk, DiffLine } from "./types.js";
66
77const execFileAsync = promisify ( execFile ) ;
88
9+ // Cap on a single git/gh stdout. Generous because a whole-PR `git diff` or a `git show` of a large
10+ // generated/vendored file can be big; exceeding it rejects (git()) or degrades a file to a spurious
11+ // full add/delete (fileAt swallows the error), so a too-small cap silently corrupts a large diff.
12+ const MAX_BUFFER = 256 * 1024 * 1024 ;
13+
914export async function git ( args : string [ ] , cwd : string ) {
10- const { stdout } = await execFileAsync ( "git" , args , { cwd, maxBuffer : 50 * 1024 * 1024 } ) ;
15+ const { stdout } = await execFileAsync ( "git" , args , { cwd, maxBuffer : MAX_BUFFER } ) ;
1116 return String ( stdout ) . trimEnd ( ) ;
1217}
1318
1419// Thin wrapper around the GitHub CLI, used only to resolve a PR number/URL to its branch.
1520// Kept optional: callers catch failures (gh missing or unauthenticated) and report them.
1621export async function gh ( args : string [ ] , cwd : string ) {
17- const { stdout } = await execFileAsync ( "gh" , args , { cwd, maxBuffer : 50 * 1024 * 1024 } ) ;
22+ const { stdout } = await execFileAsync ( "gh" , args , { cwd, maxBuffer : MAX_BUFFER } ) ;
1823 return String ( stdout ) . trimEnd ( ) ;
1924}
2025
@@ -126,7 +131,7 @@ export async function fileAt(root: string, rel: string | undefined, ref?: string
126131 if ( ref ) {
127132 const { stdout } = await execFileAsync ( "git" , [ "show" , `${ ref } :${ rel } ` ] , {
128133 cwd : root ,
129- maxBuffer : 50 * 1024 * 1024 ,
134+ maxBuffer : MAX_BUFFER ,
130135 } ) ;
131136 return String ( stdout ) ;
132137 }
0 commit comments