(cmdArgs, path, cb, options)
| 8 | var Async = require('async'); |
| 9 | |
| 10 | function exec(cmdArgs, path, cb, options) { |
| 11 | var timeout = (options && options.timeout) || 600000; |
| 12 | var autoRetry = options && options.autoRetry; |
| 13 | var autoKill = !options || (options.autoKill !== false); |
| 14 | |
| 15 | console.log(Chalk.yellow('git ' + cmdArgs.join(' ')), 'in', Chalk.magenta(path)); |
| 16 | |
| 17 | var child = Spawn('git', cmdArgs, { |
| 18 | cwd: path, |
| 19 | stdio: [0, 'pipe', 'pipe'] |
| 20 | }); |
| 21 | |
| 22 | var offbranch = false; |
| 23 | var aborted = false; |
| 24 | var timerId = -1; |
| 25 | |
| 26 | function retry () { |
| 27 | console.log(Chalk.yellow(`restart "${cmdArgs[0]}": ${Path.basename(path)}`)); |
| 28 | exec(cmdArgs, path, cb, options); // Object.assign({}, options, { autoRetry: false }) |
| 29 | } |
| 30 | |
| 31 | function onConnectionError () { |
| 32 | aborted = true; |
| 33 | clearTimeout(timerId); |
| 34 | console.log(Chalk.yellow(`connection timeout/error: ${Path.basename(path)}`)); |
| 35 | treekill(child.pid); |
| 36 | if (autoRetry && !offbranch) { |
| 37 | retry(); |
| 38 | } |
| 39 | else { |
| 40 | // console.log('+++send callback from connection timeout: ' + Path.basename(path)); |
| 41 | cb(null, { offbranch }); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | timerId = setTimeout(onConnectionError, timeout); |
| 46 | |
| 47 | child.stdout.on('data', function (data) { |
| 48 | if (aborted) return; |
| 49 | |
| 50 | var text = path + ' ' + data.toString().trim(); |
| 51 | |
| 52 | // git stash pop |
| 53 | if (text.indexOf('CONFLICT (content): Merge conflict in') !== -1) { |
| 54 | console.error(Chalk.red(text)); |
| 55 | process.exit(1); |
| 56 | } |
| 57 | }); |
| 58 | child.stderr.on('data', function(data) { |
| 59 | if (aborted) return; |
| 60 | |
| 61 | var text = path + ' ' + data.toString().trim(); |
| 62 | |
| 63 | // git checkout ("overwritten by checkout") |
| 64 | // git pull ("overwritten by merge") |
| 65 | if (text.includes('Your local changes to the following files would be overwritten by')) { |
| 66 | if (!autoKill) { |
| 67 | console.log(Chalk.yellow(text)); |
no test coverage detected