Skip to content

Commit

Permalink
Fix currentTag not returning correctly found tag (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza authored Feb 12, 2021
1 parent 71c8216 commit cd76390
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
9 changes: 6 additions & 3 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit cd76390

Please sign in to comment.