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

feat(git): accept git path option #164

Merged
merged 2 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})