| 369 | } |
| 370 | |
| 371 | async exec( |
| 372 | args: string[], |
| 373 | { |
| 374 | encoding = 'utf8', |
| 375 | allowAllExitCodes = false, |
| 376 | suppressGitCmdOutput = false |
| 377 | }: ExecOpts = {} |
| 378 | ): Promise<GitOutput> { |
| 379 | const result = new GitOutput() |
| 380 | |
| 381 | if (process.env['CPR_SHOW_GIT_CMD_OUTPUT']) { |
| 382 | // debug mode overrides the suppressGitCmdOutput option |
| 383 | suppressGitCmdOutput = false |
| 384 | } |
| 385 | |
| 386 | const env = {} |
| 387 | for (const key of Object.keys(process.env)) { |
| 388 | env[key] = process.env[key] |
| 389 | } |
| 390 | |
| 391 | const stdout: Buffer[] = [] |
| 392 | let stdoutLength = 0 |
| 393 | const stderr: Buffer[] = [] |
| 394 | let stderrLength = 0 |
| 395 | |
| 396 | const options = { |
| 397 | cwd: this.workingDirectory, |
| 398 | env, |
| 399 | ignoreReturnCode: allowAllExitCodes, |
| 400 | listeners: { |
| 401 | stdout: (data: Buffer) => { |
| 402 | stdout.push(data) |
| 403 | stdoutLength += data.length |
| 404 | }, |
| 405 | stderr: (data: Buffer) => { |
| 406 | stderr.push(data) |
| 407 | stderrLength += data.length |
| 408 | } |
| 409 | }, |
| 410 | outStream: outStreamHandler(process.stdout, suppressGitCmdOutput), |
| 411 | errStream: outStreamHandler(process.stderr, suppressGitCmdOutput) |
| 412 | } |
| 413 | |
| 414 | result.exitCode = await exec.exec(`"${this.gitPath}"`, args, options) |
| 415 | result.stdout = Buffer.concat(stdout, stdoutLength).toString(encoding) |
| 416 | result.stderr = Buffer.concat(stderr, stderrLength).toString(encoding) |
| 417 | return result |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | class GitOutput { |