fix: do not log outated branch error for missing permission cases

This commit is contained in:
Pierre Vanduynslager 2018-10-17 15:26:26 -04:00
parent e29110103b
commit 0578c8b91c
2 changed files with 15 additions and 11 deletions

View File

@ -59,14 +59,20 @@ async function run(context, plugins) {
options.repositoryUrl = await getGitAuthUrl(context); options.repositoryUrl = await getGitAuthUrl(context);
try { try {
await verifyAuth(options.repositoryUrl, options.branch, {cwd, env}); try {
} catch (error) { await verifyAuth(options.repositoryUrl, options.branch, {cwd, env});
if (!(await isBranchUpToDate(options.branch, {cwd, env}))) { } catch (error) {
logger.log( console.error('call isBranchUpToDate');
`The local branch ${options.branch} is behind the remote one, therefore a new version won't be published.` if (!(await isBranchUpToDate(options.branch, {cwd, env}))) {
); logger.log(
return false; `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}.`); logger.error(`The command "${error.cmd}" failed with the error message ${error.stderr}.`);
throw getError('EGITNOPERMISSION', {options}); throw getError('EGITNOPERMISSION', {options});
} }

View File

@ -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. * @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) { async function isBranchUpToDate(branch, execaOpts) {
const remoteHead = await execa.stdout('git', ['ls-remote', '--heads', 'origin', branch], execaOpts);
try { try {
return await isRefInHistory( return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], execaOpts);
(await execa.stdout('git', ['ls-remote', '--heads', 'origin', branch], execaOpts)).match(/^(\w+)?/)[1],
execaOpts
);
} catch (error) { } catch (error) {
debug(error); debug(error);
} }