mirror of
https://github.com/nodejs/node.git
synced 2025-05-14 06:21:00 +00:00

PR-URL: https://github.com/nodejs/node/pull/35474 Reviewed-By: Ruy Adorno <ruyadorno@github.com> Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org> Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
const spawn = require('@npmcli/promise-spawn')
|
|
const promiseRetry = require('promise-retry')
|
|
const shouldRetry = require('./should-retry.js')
|
|
const whichGit = require('./which.js')
|
|
const makeOpts = require('./opts.js')
|
|
const procLog = require('./proc-log.js')
|
|
|
|
module.exports = (gitArgs, opts = {}) => {
|
|
const gitPath = whichGit(opts)
|
|
|
|
if (gitPath instanceof Error)
|
|
return Promise.reject(gitPath)
|
|
|
|
const log = opts.log || procLog
|
|
return promiseRetry((retry, number) => {
|
|
if (number !== 1)
|
|
log.silly('pacote', `Retrying git command: ${
|
|
gitArgs.join(' ')} attempt # ${number}`)
|
|
|
|
return spawn(gitPath, gitArgs, makeOpts(opts))
|
|
.catch(er => {
|
|
if (shouldRetry(er.stderr, number))
|
|
retry(er)
|
|
else
|
|
throw er
|
|
})
|
|
}, opts.retry !== null && opts.retry !== undefined ? opts.retry : {
|
|
retries: opts.fetchRetries || 2,
|
|
factor: opts.fetchRetryFactor || 10,
|
|
maxTimeout: opts.fetchRetryMaxtimeout || 60000,
|
|
minTimeout: opts.fetchRetryMintimeout || 1000,
|
|
})
|
|
}
|