Sha256: ddbc6c566eda722680546dde33001210dda52bf4535be1e5041a06ea6d6dd8ec

Contents?: true

Size: 1.27 KB

Versions: 33

Compression:

Stored size: 1.27 KB

Contents

const spawn = require('@npmcli/promise-spawn')
const promiseRetry = require('promise-retry')
const log = require('proc-log')
const makeError = require('./make-error.js')
const whichGit = require('./which.js')
const makeOpts = require('./opts.js')

module.exports = (gitArgs, opts = {}) => {
  const gitPath = whichGit(opts)

  if (gitPath instanceof Error) {
    return Promise.reject(gitPath)
  }

  // undocumented option, mostly only here for tests
  const args = opts.allowReplace || gitArgs[0] === '--no-replace-objects'
    ? gitArgs
    : ['--no-replace-objects', ...gitArgs]

  let retryOpts = opts.retry
  if (retryOpts === null || retryOpts === undefined) {
    retryOpts = {
      retries: opts.fetchRetries || 2,
      factor: opts.fetchRetryFactor || 10,
      maxTimeout: opts.fetchRetryMaxtimeout || 60000,
      minTimeout: opts.fetchRetryMintimeout || 1000,
    }
  }
  return promiseRetry((retryFn, number) => {
    if (number !== 1) {
      log.silly('git', `Retrying git command: ${
        args.join(' ')} attempt # ${number}`)
    }

    return spawn(gitPath, args, makeOpts(opts))
      .catch(er => {
        const gitError = makeError(er)
        if (!gitError.shouldRetry(number)) {
          throw gitError
        }
        retryFn(gitError)
      })
  }, retryOpts)
}

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.60 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.59 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.58 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.57 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.56 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.55 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.54 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.53 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.52 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.51 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.50 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.49 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.48 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.47 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.46 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.45 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.44 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.43 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.42 node_modules/@npmcli/git/lib/spawn.js
immosquare-cleaner-0.1.41 node_modules/@npmcli/git/lib/spawn.js