mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-15 07:28:05 +00:00
Merge pull request #285610 from microsoft/dev/dmitriv/git-spawn-stdio-null
Do not assume stdio fields to be defined when spawning a child process.
This commit is contained in:
@@ -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');
|
||||
@@ -2684,19 +2692,23 @@ export class Repository {
|
||||
|
||||
if (limit !== 0 && parser.status.length > limit) {
|
||||
child.removeListener('close', onClose);
|
||||
child.stdout!.removeListener('data', onStdoutData);
|
||||
child.stdout?.removeListener('data', onStdoutData);
|
||||
child.kill();
|
||||
|
||||
c({ status: parser.status.slice(0, limit), statusLength: parser.status.length, didHitLimit: true });
|
||||
}
|
||||
};
|
||||
|
||||
child.stdout!.setEncoding('utf8');
|
||||
child.stdout!.on('data', onStdoutData);
|
||||
if (child.stdout) {
|
||||
child.stdout.setEncoding('utf8');
|
||||
child.stdout.on('data', onStdoutData);
|
||||
}
|
||||
|
||||
const stderrData: string[] = [];
|
||||
child.stderr!.setEncoding('utf8');
|
||||
child.stderr!.on('data', raw => stderrData.push(raw as string));
|
||||
if (child.stderr) {
|
||||
child.stderr.setEncoding('utf8');
|
||||
child.stderr.on('data', raw => stderrData.push(raw as string));
|
||||
}
|
||||
|
||||
child.on('error', cpErrorHandler(e));
|
||||
child.on('close', onClose);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user