mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-19 14:22:19 +01:00
Add more stdio checks when spawning git processes.
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');
|
||||
|
||||
@@ -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