Skip to content

Commit b0e12d5

Browse files
committed
Simplify test-lib/git
The optional options argument is never used, so neither is stdout/stderr in the resolved Promise value. Remove the unused code and unnecessary pify dependency. Add a comment about get-exec-file which returns ChildProcess with then/catch for use as a Promise in case we need it later. Signed-off-by: Kevin Locke <[email protected]>
1 parent 342ec24 commit b0e12d5

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

test-lib/git.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,21 @@
66
'use strict';
77

88
const { execFile } = require('child_process');
9-
const pify = require('pify');
9+
const util = require('util');
1010

11-
const execFileP = pify(execFile, { multiArgs: true });
11+
const execFileP = util.promisify(execFile);
1212

1313
/**
1414
* Run git with given arguments and options.
15-
* @param {...string} args Arguments to pass to git. Last argument may be an
16-
* options object.
15+
* @param {...string} args Arguments to pass to git.
1716
* @return {Promise} Promise with the process output or Error for non-0 exit.
1817
*/
1918
function git(...args) {
20-
// Default to redirecting stdin (to prevent unexpected prompts) and
21-
// including any output with test output
22-
const defaultStdio = ['ignore', process.stdout, process.stderr];
23-
24-
let options;
25-
if (typeof args[args.length - 1] === 'object') {
26-
options = args.pop();
27-
options.stdio = options.stdio || defaultStdio;
28-
} else {
29-
options = {
30-
stdio: defaultStdio,
31-
};
32-
}
33-
34-
return execFileP('git', args, options);
19+
// Ignore stdin to prevent hanging on unexpected prompts.
20+
// Inherit stdout/stderr to include any output with test output.
21+
const stdio = ['ignore', 'inherit', 'inherit'];
22+
// Note: To return stderr or ChildProcess, consider using get-exec-file
23+
return execFileP('git', args, { stdio });
3524
}
3625

3726
module.exports = git;

0 commit comments

Comments
 (0)