summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/@npmcli/git/lib/spawn.js
blob: 3c3a943fe9f0d38caa2bad5aa063badbc1b964e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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,
  })
}