Skip to content

Commit cd76390

Browse files
authored
Fix currentTag not returning correctly found tag (#8)
1 parent 71c8216 commit cd76390

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

__tests__/git.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ describe('Git commands', () => {
8888

8989
const settings = {} as Settings
9090
settings.gitPath = await io.which('git', true)
91-
settings.tagRegex = RegExp('[0-9]+.[0-9]+.[0-9]+.*', 'i')
91+
settings.tagRegex = RegExp('^[0-9]+.[0-9]+.[0-9]+.*', 'i')
9292
const g = new Git(settings)
9393

9494
await createAndCommitFile('first', 'First commit', cwd)
9595
await createTag('0.0.1', cwd)
9696

9797
const tag = await g.currentTag()
98-
expect(tag).toEqual('')
98+
expect(tag).toEqual('0.0.1')
9999
})
100100

101101
it('Verifies previous tag is returned', async () => {

src/git.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ export class Git {
1818

1919
// In case there are multiple tags get the first valid version tag
2020
if (this.settings.tagRegex) {
21+
let foundTag = ''
2122
res.stdout.forEach(tag => {
2223
if (this.settings.tagRegex.test(tag)) {
23-
return tag
24+
foundTag = tag
25+
return
2426
}
2527
})
26-
// No tag matched
27-
return ''
28+
29+
// Return either matched tag or none
30+
return foundTag
2831
}
2932
// Get the first tag we found if there's no tag regex
3033
return res.stdout[0]

0 commit comments

Comments
 (0)