fix: use unauthenticated URL to check if branch is up to date
In case the authentication token provided is unauthorized the call to `isBranchUpToDate` will fail due to lack of read permission if that URL is used. As a result the error about outdated local branch will be reported instead of the one about missing permission. By using the original (unauthenticated) URL `isBranchUpToDate` shouldn't fail due to permission as it requires only read permissions, that are necessarly present as the CI wass able to clone the repo.
This commit is contained in:
parent
eb22f9998d
commit
071dccea4b
2
index.js
2
index.js
@ -59,7 +59,7 @@ async function run(options, plugins) {
|
|||||||
try {
|
try {
|
||||||
await verifyAuth(options.repositoryUrl, options.branch);
|
await verifyAuth(options.repositoryUrl, options.branch);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!(await isBranchUpToDate(options.repositoryUrl, options.branch))) {
|
if (!(await isBranchUpToDate(options.branch))) {
|
||||||
logger.log(
|
logger.log(
|
||||||
"The local branch %s is behind the remote one, therefore a new version won't be published.",
|
"The local branch %s is behind the remote one, therefore a new version won't be published.",
|
||||||
options.branch
|
options.branch
|
||||||
|
@ -145,15 +145,14 @@ async function verifyTagName(tagName) {
|
|||||||
/**
|
/**
|
||||||
* Verify the local branch is up to date with the remote one.
|
* Verify the local branch is up to date with the remote one.
|
||||||
*
|
*
|
||||||
* @param {String} repositoryUrl The remote repository URL.
|
|
||||||
* @param {String} branch The repository branch for which to verify status.
|
* @param {String} branch The repository branch for which to verify status.
|
||||||
*
|
*
|
||||||
* @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(repositoryUrl, branch) {
|
async function isBranchUpToDate(branch) {
|
||||||
try {
|
try {
|
||||||
return await isRefInHistory(
|
return await isRefInHistory(
|
||||||
(await execa.stdout('git', ['ls-remote', '--heads', repositoryUrl, branch])).match(/^(\w+)?/)[1]
|
(await execa.stdout('git', ['ls-remote', '--heads', 'origin', branch])).match(/^(\w+)?/)[1]
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debug(err);
|
debug(err);
|
||||||
|
@ -206,11 +206,11 @@ test.serial('Throws error if obtaining the tags fails', async t => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test.serial('Return "true" if repository is up to date', async t => {
|
test.serial('Return "true" if repository is up to date', async t => {
|
||||||
const repositoryUrl = await gitRepo(true);
|
await gitRepo(true);
|
||||||
await gitCommits(['First']);
|
await gitCommits(['First']);
|
||||||
await gitPush();
|
await gitPush();
|
||||||
|
|
||||||
t.true(await isBranchUpToDate(repositoryUrl, 'master'));
|
t.true(await isBranchUpToDate('master'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test.serial('Return falsy if repository is not up to date', async t => {
|
test.serial('Return falsy if repository is not up to date', async t => {
|
||||||
@ -220,21 +220,21 @@ test.serial('Return falsy if repository is not up to date', async t => {
|
|||||||
await gitCommits(['Second']);
|
await gitCommits(['Second']);
|
||||||
await gitPush();
|
await gitPush();
|
||||||
|
|
||||||
t.true(await isBranchUpToDate(repositoryUrl, 'master'));
|
t.true(await isBranchUpToDate('master'));
|
||||||
|
|
||||||
await gitShallowClone(repositoryUrl);
|
await gitShallowClone(repositoryUrl);
|
||||||
await gitCommits(['Third']);
|
await gitCommits(['Third']);
|
||||||
await gitPush();
|
await gitPush();
|
||||||
process.chdir(repoDir);
|
process.chdir(repoDir);
|
||||||
|
|
||||||
t.falsy(await isBranchUpToDate(repositoryUrl, 'master'));
|
t.falsy(await isBranchUpToDate('master'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test.serial('Return "true" if local repository is ahead', async t => {
|
test.serial('Return "true" if local repository is ahead', async t => {
|
||||||
const repositoryUrl = await gitRepo(true);
|
await gitRepo(true);
|
||||||
await gitCommits(['First']);
|
await gitCommits(['First']);
|
||||||
await gitPush();
|
await gitPush();
|
||||||
await gitCommits(['Second']);
|
await gitCommits(['Second']);
|
||||||
|
|
||||||
t.true(await isBranchUpToDate(repositoryUrl, 'master'));
|
t.true(await isBranchUpToDate('master'));
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user