diff --git a/index.js b/index.js index fffd367c..a2de3b12 100644 --- a/index.js +++ b/index.js @@ -59,14 +59,20 @@ async function run(context, plugins) { options.repositoryUrl = await getGitAuthUrl(context); try { - await verifyAuth(options.repositoryUrl, options.branch, {cwd, env}); - } catch (error) { - if (!(await isBranchUpToDate(options.branch, {cwd, env}))) { - logger.log( - `The local branch ${options.branch} is behind the remote one, therefore a new version won't be published.` - ); - return false; + try { + await verifyAuth(options.repositoryUrl, options.branch, {cwd, env}); + } catch (error) { + console.error('call isBranchUpToDate'); + if (!(await isBranchUpToDate(options.branch, {cwd, env}))) { + logger.log( + `The local branch ${options.branch} is behind the remote one, therefore a new version won't be published.` + ); + return false; + } + console.error('call throw error'); + throw error; } + } catch (error) { logger.error(`The command "${error.cmd}" failed with the error message ${error.stderr}.`); throw getError('EGITNOPERMISSION', {options}); } diff --git a/lib/git.js b/lib/git.js index b03d8f49..9ecd9dc2 100644 --- a/lib/git.js +++ b/lib/git.js @@ -177,11 +177,9 @@ async function verifyTagName(tagName, execaOpts) { * @return {Boolean} `true` is the HEAD of the current local branch is the same as the HEAD of the remote branch, falsy otherwise. */ async function isBranchUpToDate(branch, execaOpts) { + const remoteHead = await execa.stdout('git', ['ls-remote', '--heads', 'origin', branch], execaOpts); try { - return await isRefInHistory( - (await execa.stdout('git', ['ls-remote', '--heads', 'origin', branch], execaOpts)).match(/^(\w+)?/)[1], - execaOpts - ); + return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], execaOpts); } catch (error) { debug(error); }