@@ -11,6 +11,11 @@ import (
11
11
"github.com/go-git/go-git/v5/plumbing/object"
12
12
)
13
13
14
+ var (
15
+ latestTag * plumbing.Reference
16
+ previousTag * plumbing.Reference
17
+ )
18
+
14
19
// GetLatestTagFromRepository - Get the latest Tag reference from the repo
15
20
func GetLatestTagFromRepository (repository * git.Repository ) (* plumbing.Reference , * plumbing.Reference , error ) {
16
21
tagRefs , err := repository .Tags ()
@@ -61,7 +66,13 @@ func GetLatestTagFromRepository(repository *git.Repository) (*plumbing.Reference
61
66
62
67
// isCommitToNearestTag - go through git revisions to find the latest tag and the nearest next tag
63
68
func isCommitToNearestTag (repo * git.Repository , commit * object.Commit ) bool {
64
- latestTag , previousTag , err := GetLatestTagFromRepository (repo )
69
+ if latestTag == nil || previousTag == nil {
70
+ var err error
71
+ latestTag , previousTag , err = GetLatestTagFromRepository (repo )
72
+ if err != nil {
73
+ log .Fatal ("Error getting latest tags from repository" )
74
+ }
75
+ }
65
76
66
77
ref , err := repo .Head ()
67
78
@@ -77,9 +88,9 @@ func isCommitToNearestTag(repo *git.Repository, commit *object.Commit) bool {
77
88
78
89
if latestTag != nil && previousTag != nil {
79
90
if tillLatest {
80
- return latestTag .Hash (). String () == commit .Hash . String ()
91
+ return latestTag .Hash () == commit .Hash
81
92
}
82
- return previousTag .Hash (). String () == commit .Hash . String ()
93
+ return previousTag .Hash () == commit .Hash
83
94
84
95
}
85
96
return false
0 commit comments