Skip to content

Fix currentTag not returning correctly found tag #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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