Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
feat(git): accept git path option (#164)
Browse files Browse the repository at this point in the history
* feat(git): accept git path option

Allow option detailing the git binary path.

See https://npm.community/t/3278

* test(git): fix git test for windows

Fix git test for windows, specifically '\r\n' vs '\n'.
  • Loading branch information
larsgw authored and zkat committed Nov 26, 2018
1 parent aaff4de commit f06c8c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/util/opt-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = figgyPudding({
fullMetadata: 'full-metadata',
'full-metadata': { default: false },
gid: {},
git: {},
includeDeprecated: { default: true },
'include-deprecated': 'includeDeprecated',
integrity: {},
Expand Down
10 changes: 10 additions & 0 deletions test/util.git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

0 comments on commit f06c8c5

Please sign in to comment.