From 2bc1a89e142ad464ee9666e313589205a30b29cc Mon Sep 17 00:00:00 2001 From: bridiver Date: Tue, 2 Jun 2020 08:42:22 -0700 Subject: [PATCH] default to continueOnFail === false and handle failures for continueOnFail === true --- lib/util.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/util.js b/lib/util.js index 9f85c8010..7fa4ed6bb 100755 --- a/lib/util.js +++ b/lib/util.js @@ -121,9 +121,16 @@ const util = { }) }, - runGit: function (repoPath, gitArgs, continueOnFail = true) { - return util.run('git', gitArgs, { cwd: repoPath, continueOnFail }) - .stdout.toString().trim() + runGit: function (repoPath, gitArgs, continueOnFail = false) { + let prog = util.run('git', gitArgs, { cwd: repoPath, continueOnFail }) + + if (prog.status !== 0) { + console.error(prog.stdout) + console.error(prog.stderr) + return null + } else { + return prog.stdout.toString().trim() + } }, runGitAsync: function (repoPath, gitArgs, verbose = false, logError = false) { @@ -584,20 +591,20 @@ const util = { const braveCoreRef = config.getProjectVersion('brave-core') Log.status(`Cloning brave-core [${braveCoreRef}] into ${config.braveCoreDir}...`) fs.mkdirSync(config.braveCoreDir) - util.runGit(config.braveCoreDir, ['clone', config.braveCoreRepo, '.'], false) - util.runGit(config.braveCoreDir, ['checkout', braveCoreRef], false) + util.runGit(config.braveCoreDir, ['clone', config.braveCoreRepo, '.']) + util.runGit(config.braveCoreDir, ['checkout', braveCoreRef]) } }, shouldUpdateChromium: (chromiumRef = config.getProjectRef('chrome')) => { util.runGit(config.srcDir, ['fetch', '--all', '--tags']) - const headSHA = util.runGit(config.srcDir, ['rev-parse', 'HEAD'], false) - const targetSHA = util.runGit(config.srcDir, ['rev-parse', chromiumRef], false) - const needsUpdate = (targetSHA !== headSHA) + const headSHA = util.runGit(config.srcDir, ['rev-parse', 'HEAD'], true) + const targetSHA = util.runGit(config.srcDir, ['rev-parse', chromiumRef], true) + const needsUpdate = ((targetSHA !== headSHA) || (!headSHA && !targetSHA)) if (needsUpdate) { - console.log(`Chromium repo ${chalk.blue.bold('needs update')}. Target is ${chalk.italic(chromiumRef)} at commit ${targetSHA} but current commit is ${chalk.inverse(headSHA)}.`) + console.log(`Chromium repo ${chalk.blue.bold('needs update')}. Target is ${chalk.italic(chromiumRef)} at commit ${targetSHA || '[missing]'} but current commit is ${chalk.inverse(headSHA || '[missing]')}.`) } else { - console.log(chalk.green.bold(`Chromium repo does not need update as it is already ${chalk.italic(chromiumRef)} at commit ${targetSHA}.`)) + console.log(chalk.green.bold(`Chromium repo does not need update as it is already ${chalk.italic(chromiumRef)} at commit ${targetSHA || '[missing]'}.`)) } return needsUpdate }, @@ -617,10 +624,10 @@ const util = { // Use current branch (sync will then pull latest) or current exact hash // if we're not in a branch. util.runGit(config.braveCoreDir, ['fetch', '--all', '--tags']) - braveCoreRef = util.runGit(config.braveCoreDir, ['rev-parse', '--abbrev-ref', 'HEAD'], false) + braveCoreRef = util.runGit(config.braveCoreDir, ['rev-parse', '--abbrev-ref', 'HEAD']) if (braveCoreRef === 'HEAD') { // get the rev hash if we're not in a branch - braveCoreRef = util.runGit(config.braveCoreDir, ['rev-parse', 'HEAD'], false) + braveCoreRef = util.runGit(config.braveCoreDir, ['rev-parse', 'HEAD']) } }