fix: use git ls-remote to verify if the remote branch is ahead

This commit is contained in:
Pierre Vanduynslager
2018-06-15 16:16:55 -04:00
parent 24a8052038
commit 2b6378f26f
6 changed files with 35 additions and 31 deletions
+12 -9
View File
@@ -24,7 +24,6 @@ import {
gitCommitTag,
gitRemoteTagHead,
push as pushUtil,
reset,
} from './helpers/git-utils';
// Save the current working diretory
@@ -189,31 +188,35 @@ test.serial('Throws error if obtaining the tags fails', async t => {
});
test.serial('Return "true" if repository is up to date', async t => {
await gitRepo(true);
const repositoryUrl = await gitRepo(true);
await gitCommits(['First']);
await pushUtil();
t.true(await isBranchUpToDate('master'));
t.true(await isBranchUpToDate(repositoryUrl, 'master'));
});
test.serial('Return falsy if repository is not up to date', async t => {
await gitRepo(true);
const repositoryUrl = await gitRepo(true);
const repoDir = process.cwd();
await gitCommits(['First']);
await gitCommits(['Second']);
await pushUtil();
t.true(await isBranchUpToDate('master'));
t.true(await isBranchUpToDate(repositoryUrl, 'master'));
await reset();
await gitShallowClone(repositoryUrl);
await gitCommits(['Third']);
await pushUtil();
process.chdir(repoDir);
t.falsy(await isBranchUpToDate('master'));
t.falsy(await isBranchUpToDate(repositoryUrl, 'master'));
});
test.serial('Return "true" if local repository is ahead', async t => {
await gitRepo(true);
const repositoryUrl = await gitRepo(true);
await gitCommits(['First']);
await pushUtil();
await gitCommits(['Second']);
t.true(await isBranchUpToDate('master'));
t.true(await isBranchUpToDate(repositoryUrl, 'master'));
});
-9
View File
@@ -212,12 +212,3 @@ export async function gitCommitTag(gitHead) {
export async function push(repositoryUrl = 'origin', branch = 'master') {
await execa('git', ['push', '--tags', repositoryUrl, `HEAD:${branch}`]);
}
/**
* Reset repository to a commit.
*
* @param {String} [commit='HEAD~1'] Commit reference to reset the repo to.
*/
export async function reset(commit = 'HEAD~1') {
await execa('git', ['reset', commit]);
}
+5 -2
View File
@@ -15,7 +15,6 @@ import {
gitRemoteTagHead,
push,
gitShallowClone,
reset,
} from './helpers/git-utils';
// Save the current process.env
@@ -645,11 +644,15 @@ test.serial('Returns falsy value if triggered by a PR', async t => {
test.serial('Returns falsy value if triggered on an outdated clone', async t => {
// Create a git repository, set the current working directory at the root of the repo
const repositoryUrl = await gitRepo(true);
const repoDir = process.cwd();
// Add commits to the master branch
await gitCommits(['First']);
await gitCommits(['Second']);
await push();
await reset();
await gitShallowClone(repositoryUrl);
await gitCommits(['Third']);
await push();
process.chdir(repoDir);
const semanticRelease = proxyquire('..', {
'./lib/logger': t.context.logger,
+2 -1
View File
@@ -2,7 +2,7 @@ import test from 'ava';
import {writeJson, readJson} from 'fs-extra';
import {stub} from 'sinon';
import execa from 'execa';
import {gitHead as getGitHead, gitTagHead, gitRepo, gitCommits, gitRemoteTagHead} from './helpers/git-utils';
import {gitHead as getGitHead, gitTagHead, gitRepo, gitCommits, gitRemoteTagHead, push} from './helpers/git-utils';
import gitbox from './helpers/gitbox';
import mockServer from './helpers/mockserver';
import npmRegistry from './helpers/npm-registry';
@@ -609,6 +609,7 @@ test.serial('Exit with 1 if missing permission to push to the remote repository'
/* Initial release */
t.log('Commit a feature');
await gitCommits(['feat: Initial commit']);
await push();
t.log('$ semantic-release');
const {stdout, code} = await execa(
cli,