Add more stdio checks when spawning git processes.

This commit is contained in:
Dmitriy Vasyura
2026-01-02 16:47:47 -08:00
parent 96bd5f640b
commit be8b8bfdcc
2 changed files with 26 additions and 6 deletions
+9 -1
View File
@@ -1924,7 +1924,15 @@ export class Repository {
async stage(path: string, data: Uint8Array): Promise<void> {
const relativePath = this.sanitizeRelativePath(path);
const child = this.stream(['hash-object', '--stdin', '-w', '--path', relativePath], { stdio: [null, null, null] });
child.stdin!.end(data);
if (!child.stdin) {
throw new GitError({
message: 'Failed to spawn git process',
exitCode: -1
});
}
child.stdin.end(data);
const { exitCode, stdout } = await exec(child);
const hash = stdout.toString('utf8');
+17 -5
View File
@@ -2347,7 +2347,15 @@ export class Repository implements Disposable {
// https://git-scm.com/docs/git-check-ignore#git-check-ignore--z
const child = this.repository.stream(['check-ignore', '-v', '-z', '--stdin'], { stdio: [null, null, null] });
child.stdin!.end(filePaths.join('\0'), 'utf8');
if (!child.stdin) {
return reject(new GitError({
message: 'Failed to spawn git process',
exitCode: -1
}));
}
child.stdin.end(filePaths.join('\0'), 'utf8');
const onExit = (exitCode: number) => {
if (exitCode === 1) {
@@ -2369,12 +2377,16 @@ export class Repository implements Disposable {
data += raw;
};
child.stdout!.setEncoding('utf8');
child.stdout!.on('data', onStdoutData);
if (child.stdout) {
child.stdout.setEncoding('utf8');
child.stdout.on('data', onStdoutData);
}
let stderr: string = '';
child.stderr!.setEncoding('utf8');
child.stderr!.on('data', raw => stderr += raw);
if (child.stderr) {
child.stderr.setEncoding('utf8');
child.stderr.on('data', raw => stderr += raw);
}
child.on('error', reject);
child.on('exit', onExit);