Skip to content

Commit

Permalink
Allow wildcards for required branch(es) (closes #877)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Mar 19, 2022
1 parent 739f6f6 commit fb8622b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/git.md
Expand Up @@ -96,7 +96,7 @@ This is disabled by default, but release-it can exit the process when the curren
}
```

Use an array to allow releases from more branch names.
Use an array to allow releases from more branch names. Wildcards are also allowed (e.g. `release/*`).

### Clean working directory

Expand Down
3 changes: 2 additions & 1 deletion lib/plugin/git/Git.js
@@ -1,6 +1,7 @@
const { EOL } = require('os');
const _ = require('lodash');
const execa = require('execa');
const matcher = require('wildcard-match');
const { format, e } = require('../../util');
const GitBase = require('../GitBase');
const prompts = require('./prompts');
Expand Down Expand Up @@ -94,7 +95,7 @@ class Git extends GitBase {
async isRequiredBranch() {
const branch = await this.getBranchName();
const requiredBranches = _.castArray(this.options.requireBranch);
return requiredBranches.includes(branch);
return matcher(requiredBranches)(branch);
}

async hasUpstreamBranch() {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -81,6 +81,7 @@
"update-notifier": "5.1.0",
"url-join": "4.0.1",
"uuid": "8.3.2",
"wildcard-match": "5.1.2",
"yaml": "1.10.2",
"yargs-parser": "20.2.9"
},
Expand Down
13 changes: 13 additions & 0 deletions test/git.init.js
Expand Up @@ -24,6 +24,19 @@ test.serial('should throw if on wrong branch', async t => {
await t.throwsAsync(gitClient.init(), { message: /^Must be on branch dev/ });
});

test.serial('should not throw if required branch matches', async t => {
const options = { git: { requireBranch: 'ma?*' } };
const gitClient = factory(Git, { options });
await t.notThrowsAsync(gitClient.init());
});

test.serial('should not throw if one of required branch matches', async t => {
const options = { git: { requireBranch: ['release/*', 'hotfix/*'] } };
const gitClient = factory(Git, { options });
sh.exec('git checkout -b release/v1');
await t.notThrowsAsync(gitClient.init());
});

test.serial('should throw if there is no remote Git url', async t => {
const gitClient = factory(Git, { options: { git } });
sh.exec('git remote remove origin');
Expand Down

0 comments on commit fb8622b

Please sign in to comment.