From d0fb678c39a0a2631ecded6db4f3efead10eed71 Mon Sep 17 00:00:00 2001 From: Lars Willighagen Date: Tue, 20 Nov 2018 23:53:36 +0100 Subject: [PATCH 1/2] feat(git): accept git path option Allow option detailing the git binary path. See https://npm.community/t/3278 --- lib/util/git.js | 16 +++++++++------- lib/util/opt-check.js | 1 + test/util.git.js | 10 ++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/util/git.js b/lib/util/git.js index 617c29c..997404d 100644 --- a/lib/util/git.js +++ b/lib/util/git.js @@ -74,10 +74,10 @@ function fullClone (repo, committish, target, opts) { if (process.platform === 'win32') { gitArgs.push('--config', 'core.longpaths=true') } - return execGit(gitArgs, { cwd: target }).then(() => { - return execGit(['init'], { cwd: target }) + return execGit(gitArgs, { cwd: target }, opts).then(() => { + return execGit(['init'], { cwd: target }, opts) }).then(() => { - return execGit(['checkout', committish || 'HEAD'], { cwd: target }) + return execGit(['checkout', committish || 'HEAD'], { cwd: target }, opts) }).then(() => { return updateSubmodules(target, opts) }).then(() => headSha(target, opts)) @@ -182,7 +182,7 @@ function revs (repo, opts) { module.exports._exec = execGit function execGit (gitArgs, gitOpts, opts) { opts = optCheck(opts) - return checkGit().then(gitPath => { + return checkGit(opts).then(gitPath => { return promiseRetry((retry, number) => { if (number !== 1) { opts.log.silly('pacote', 'Retrying git command: ' + gitArgs.join(' ') + ' attempt # ' + number) @@ -206,7 +206,7 @@ function execGit (gitArgs, gitOpts, opts) { module.exports._spawn = spawnGit function spawnGit (gitArgs, gitOpts, opts) { opts = optCheck(opts) - return checkGit().then(gitPath => { + return checkGit(opts).then(gitPath => { return promiseRetry((retry, number) => { if (number !== 1) { opts.log.silly('pacote', 'Retrying git command: ' + gitArgs.join(' ') + ' attempt # ' + number) @@ -246,8 +246,10 @@ function mkOpts (_gitOpts, opts) { return gitOpts } -function checkGit () { - if (!GITPATH) { +function checkGit (opts) { + if (opts.git) { + return BB.resolve(opts.git) + } else if (!GITPATH) { const err = new Error('No git binary found in $PATH') err.code = 'ENOGIT' return BB.reject(err) diff --git a/lib/util/opt-check.js b/lib/util/opt-check.js index 51520d7..e6afc21 100644 --- a/lib/util/opt-check.js +++ b/lib/util/opt-check.js @@ -21,6 +21,7 @@ module.exports = figgyPudding({ fullMetadata: 'full-metadata', 'full-metadata': { default: false }, gid: {}, + git: {}, includeDeprecated: { default: true }, 'include-deprecated': 'includeDeprecated', integrity: {}, diff --git a/test/util.git.js b/test/util.git.js index daf543d..5416d48 100644 --- a/test/util.git.js +++ b/test/util.git.js @@ -15,3 +15,13 @@ test('executes git binary', { t.match(stdout, /^git version/, 'successfully ran git') }) }) + +const systemNode = which.sync('node') + +test('acknowledges git option', t => { + return git._exec(['--version'], null, { + git: systemNode + }).spread(stdout => { + t.equals(stdout, process.version + '\n') + }) +}) From dbf6d7387ffddad452f313a2c3773a266c17412f Mon Sep 17 00:00:00 2001 From: Lars Willighagen Date: Wed, 21 Nov 2018 00:02:34 +0100 Subject: [PATCH 2/2] test(git): fix git test for windows Fix git test for windows, specifically '\r\n' vs '\n'. --- test/util.git.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/util.git.js b/test/util.git.js index 5416d48..e2ea0cf 100644 --- a/test/util.git.js +++ b/test/util.git.js @@ -22,6 +22,6 @@ test('acknowledges git option', t => { return git._exec(['--version'], null, { git: systemNode }).spread(stdout => { - t.equals(stdout, process.version + '\n') + t.equals(stdout.trim(), process.version) }) })