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..e2ea0cf 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.trim(), process.version) + }) +})