diff --git a/config/release-it.json b/config/release-it.json index 48cd2190..9e9d72de 100644 --- a/config/release-it.json +++ b/config/release-it.json @@ -12,6 +12,7 @@ "commitArgs": [], "tag": true, "tagName": null, + "tagMatch": null, "tagAnnotation": "Release ${version}", "tagArgs": [], "push": true, diff --git a/docs/git.md b/docs/git.md index 06243338..99883840 100644 --- a/docs/git.md +++ b/docs/git.md @@ -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 diff --git a/lib/plugin/GitBase.js b/lib/plugin/GitBase.js index 0f2e79d6..49647b7b 100644 --- a/lib/plugin/GitBase.js +++ b/lib/plugin/GitBase.js @@ -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 diff --git a/test/git.init.js b/test/git.init.js index 513af7a4..39afadb6 100644 --- a/test/git.init.js +++ b/test/git.init.js @@ -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');