source: trip-planner-front/node_modules/@npmcli/git/lib/spawn.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1const spawn = require('@npmcli/promise-spawn')
2const promiseRetry = require('promise-retry')
3const makeError = require('./make-error.js')
4const whichGit = require('./which.js')
5const makeOpts = require('./opts.js')
6const procLog = require('./proc-log.js')
7
8module.exports = (gitArgs, opts = {}) => {
9 const gitPath = whichGit(opts)
10
11 if (gitPath instanceof Error) { return Promise.reject(gitPath) }
12
13 // undocumented option, mostly only here for tests
14 const args = opts.allowReplace || gitArgs[0] === '--no-replace-objects'
15 ? gitArgs
16 : ['--no-replace-objects', ...gitArgs]
17
18 const log = opts.log || procLog
19 let retry = opts.retry
20 if (retry === null || retry === undefined) {
21 retry = {
22 retries: opts.fetchRetries || 2,
23 factor: opts.fetchRetryFactor || 10,
24 maxTimeout: opts.fetchRetryMaxtimeout || 60000,
25 minTimeout: opts.fetchRetryMintimeout || 1000
26 }
27 }
28 return promiseRetry((retry, number) => {
29 if (number !== 1) {
30 log.silly('git', `Retrying git command: ${
31 args.join(' ')} attempt # ${number}`)
32 }
33
34 return spawn(gitPath, args, makeOpts(opts))
35 .catch(er => {
36 const gitError = makeError(er)
37 if (!gitError.shouldRetry(number)) {
38 throw gitError
39 }
40 retry(gitError)
41 })
42 }, retry)
43}
Note: See TracBrowser for help on using the repository browser.