Skip to content

Commit

Permalink
fix #34645
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Sep 20, 2017
1 parent a090257 commit 01dade3
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function findSpecificGit(path: string): Promise<IGit> {
const buffers: Buffer[] = [];
const child = cp.spawn(path, ['--version']);
child.stdout.on('data', (b: Buffer) => buffers.push(b));
child.on('error', e);
child.on('error', cpErrorHandler(e));
child.on('exit', code => code ? e(new Error('Not found')) : c({ path, version: parseVersion(Buffer.concat(buffers).toString('utf8').trim()) }));
});
}
Expand Down Expand Up @@ -159,6 +159,20 @@ export interface IExecutionResult {
stderr: string;
}

function cpErrorHandler(cb: (reason?: any) => void): (reason?: any) => void {
return err => {
if (/ENOENT/.test(err.message)) {
err = new GitError({
error: err,
message: 'Failed to execute git (ENOENT)',
gitErrorCode: GitErrorCodes.NotAGitRepository
});
}

cb(err);
};
}

async function exec(child: cp.ChildProcess, options: any = {}): Promise<IExecutionResult> {
if (!child.stdout || !child.stderr) {
throw new GitError({
Expand All @@ -183,7 +197,7 @@ async function exec(child: cp.ChildProcess, options: any = {}): Promise<IExecuti

const [exitCode, stdout, stderr] = await Promise.all<any>([
new Promise<number>((c, e) => {
once(child, 'error', e);
once(child, 'error', cpErrorHandler(e));
once(child, 'exit', c);
}),
new Promise<string>(c => {
Expand Down Expand Up @@ -919,7 +933,7 @@ export class Repository {
child.stderr.setEncoding('utf8');
child.stderr.on('data', raw => stderrData.push(raw as string));

child.on('error', e);
child.on('error', cpErrorHandler(e));
child.on('exit', onExit);
});
}
Expand Down

0 comments on commit 01dade3

Please sign in to comment.