MCPcopy Create free account
hub / github.com/cocos/cocos-engine / exec

Function exec

native/utils/git.js:10–116  ·  view source on GitHub ↗
(cmdArgs, path, cb, options)

Source from the content-addressed store, hash-verified

8var Async = require('async');
9
10function 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));

Callers 9

retryFunction · 0.85
commitFunction · 0.85
updateExternalFunction · 0.85
checkoutFunction · 0.85
fetchFunction · 0.85
checkoutTrackFunction · 0.85
pullFunction · 0.85
pushFunction · 0.85
updateOriginUrlFunction · 0.85

Calls 12

SpawnClass · 0.85
setTimeoutFunction · 0.85
cbFunction · 0.85
onConnectionErrorFunction · 0.85
logMethod · 0.80
joinMethod · 0.80
errorMethod · 0.80
onMethod · 0.65
toStringMethod · 0.65
trimMethod · 0.45
indexOfMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected