Skip to content

Commit

Permalink
Add git.tagMatch to allow custom tag matching (fixes #761)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Aug 8, 2021
1 parent 4c91cd1 commit f72ca0a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/release-it.json
Expand Up @@ -12,6 +12,7 @@
"commitArgs": [],
"tag": true,
"tagName": null,
"tagMatch": null,
"tagAnnotation": "Release ${version}",
"tagArgs": [],
"push": true,
Expand Down
15 changes: 12 additions & 3 deletions docs/git.md
Expand Up @@ -35,10 +35,19 @@ By default, `release-it` uses branch's tracking information, unless there isn't
`"origin"` as the remote name to push to. Use `git.pushRepo` to override this with a different remote name, or a
different git url.

## Tag name
## Tag Name

The `v` prefix is automatically detected from the latest tag. No need to configure e.g. `git.tagName: "v${version}"`,
unless you specifically want to override or change this.
Use `git.tagName` to set a custom tag, not equal to the (prefixed) version. The `v` prefix is automatically detected
from the latest tag. No need to configure e.g. `git.tagName: "v${version}"`.

Example: `git.tagName=${name}@${version}`

## Tag Match

Use `git.tagMatch` to override the normal matching behavior to find the latest tag. This can be useful when using a
plugin to determine the next tag.

Example: `git.tagMatch='[0-9][0-9].[0-1][0-9].[0-9]*'`

## Extra arguments

Expand Down
2 changes: 1 addition & 1 deletion lib/plugin/GitBase.js
Expand Up @@ -87,7 +87,7 @@ class GitBase extends Plugin {

getLatestTagName(repo) {
const context = Object.assign({ repo }, this.getContext(), { version: '*' });
const match = format(this.options.tagName || '${version}', context);
const match = format(this.options.tagMatch || this.options.tagName || '${version}', context);
return this.exec(`git describe --tags --match=${match} --abbrev=0`, { options }).then(
stdout => stdout || null,
() => null
Expand Down
20 changes: 20 additions & 0 deletions test/git.init.js
Expand Up @@ -138,6 +138,26 @@ test.serial('should get the latest custom tag after fetch when tagName is config
t.is(gitClient.getContext('latestTagName'), 'TAGNAME-v1.0.0');
});

test.serial('should get the latest tag based on tagMatch', async t => {
const shell = factory(Shell);
const gitClient = factory(Git, {
options: { git: { tagMatch: '[0-9][0-9].[0-1][0-9].[0-9]*' } },
container: { shell }
});
const { bare, target } = t.context;
const other = mkTmpDir();
sh.exec('git push');
sh.exec(`git clone ${bare} ${other}`);
sh.pushd('-q', other);
sh.exec('git tag 1.0.0');
sh.exec('git tag 21.04.3');
sh.exec('git tag 1.0.1');
sh.exec('git push --tags');
sh.pushd('-q', target);
await gitClient.init();
t.is(gitClient.getContext('latestTagName'), '21.04.3');
});

test.serial('should generate correct changelog', async t => {
const gitClient = factory(Git, { options: { git } });
sh.exec('git tag 1.0.0');
Expand Down

0 comments on commit f72ca0a

Please sign in to comment.