diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 8392922..6a73c34 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -88,14 +88,14 @@ describe('Git commands', () => { const settings = {} as Settings settings.gitPath = await io.which('git', true) - settings.tagRegex = RegExp('[0-9]+.[0-9]+.[0-9]+.*', 'i') + settings.tagRegex = RegExp('^[0-9]+.[0-9]+.[0-9]+.*', 'i') const g = new Git(settings) await createAndCommitFile('first', 'First commit', cwd) await createTag('0.0.1', cwd) const tag = await g.currentTag() - expect(tag).toEqual('') + expect(tag).toEqual('0.0.1') }) it('Verifies previous tag is returned', async () => { diff --git a/src/git.ts b/src/git.ts index b3d15c5..8c4af5e 100644 --- a/src/git.ts +++ b/src/git.ts @@ -18,13 +18,16 @@ export class Git { // In case there are multiple tags get the first valid version tag if (this.settings.tagRegex) { + let foundTag = '' res.stdout.forEach(tag => { if (this.settings.tagRegex.test(tag)) { - return tag + foundTag = tag + return } }) - // No tag matched - return '' + + // Return either matched tag or none + return foundTag } // Get the first tag we found if there's no tag regex return res.stdout[0]