Skip to content

Commit 81007df

Browse files
committed
Set default release branch to main or master
1 parent b4bef72 commit 81007df

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

source/git-util.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ exports.currentBranch = async () => {
3838
return stdout;
3939
};
4040

41-
exports.verifyCurrentBranchIsReleaseBranch = async (releaseBranch = 'master') => {
42-
if (await exports.currentBranch() !== releaseBranch) {
43-
throw new Error(`Not on \`${releaseBranch}\` branch. Use --any-branch to publish anyway, or set a different release branch using --branch.`);
41+
exports.verifyCurrentBranchIsReleaseBranch = async releaseBranch => {
42+
const allowedBranches = releaseBranch ? [releaseBranch] : ['main', 'master'];
43+
const currentBranch = await exports.currentBranch();
44+
if (!allowedBranches.includes(currentBranch)) {
45+
throw new Error(`Not on ${allowedBranches.map(br => `\`${br}\``).join('/')} branch. Use --any-branch to publish anyway, or set a different release branch using --branch.`);
4446
}
4547
};
4648

test/git-tasks.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ test.beforeEach(() => {
2424
execaStub.resetStub();
2525
});
2626

27+
test.serial('should fail when release branch is not specified, current branch is not main/master and publishing from any branch not permitted', async t => {
28+
execaStub.createStub([
29+
{
30+
command: 'git symbolic-ref --short HEAD',
31+
exitCode: 0,
32+
stdout: 'feature'
33+
}
34+
]);
35+
await t.throwsAsync(run(testedModule({})),
36+
{message: 'Not on `main`/`master` branch. Use --any-branch to publish anyway, or set a different release branch using --branch.'});
37+
t.true(SilentRenderer.tasks.some(task => task.title === 'Check current branch' && task.hasFailed()));
38+
});
39+
2740
test.serial('should fail when current branch is not the specified release branch and publishing from any branch not permitted', async t => {
2841
execaStub.createStub([
2942
{
@@ -32,8 +45,8 @@ test.serial('should fail when current branch is not the specified release branch
3245
stdout: 'feature'
3346
}
3447
]);
35-
await t.throwsAsync(run(testedModule({branch: 'main'})),
36-
{message: 'Not on `main` branch. Use --any-branch to publish anyway, or set a different release branch using --branch.'});
48+
await t.throwsAsync(run(testedModule({branch: 'release'})),
49+
{message: 'Not on `release` branch. Use --any-branch to publish anyway, or set a different release branch using --branch.'});
3750
t.true(SilentRenderer.tasks.some(task => task.title === 'Check current branch' && task.hasFailed()));
3851
});
3952

0 commit comments

Comments
 (0)