3
3
package commitlog
4
4
5
5
import (
6
- "fmt"
7
6
"log"
8
7
"strings"
9
8
@@ -30,7 +29,7 @@ func GetLatestTagFromRepository(repository *git.Repository) (*plumbing.Reference
30
29
var previousTagReturn * plumbing.Reference
31
30
32
31
err = tagRefs .ForEach (func (tagRef * plumbing.Reference ) error {
33
- revision := plumbing .Revision (tagRef .Name (). String () )
32
+ revision := plumbing .Revision (tagRef .Name ())
34
33
35
34
tagCommitHash , err := repository .ResolveRevision (revision )
36
35
if err != nil {
@@ -58,6 +57,7 @@ func GetLatestTagFromRepository(repository *git.Repository) (*plumbing.Reference
58
57
59
58
return nil
60
59
})
60
+
61
61
if err != nil {
62
62
return nil , nil , err
63
63
}
@@ -75,39 +75,41 @@ func isCommitToNearestTag(repo *git.Repository, commit *object.Commit) bool {
75
75
}
76
76
}
77
77
78
- revisionHashLatest , err := repo .ResolveRevision (plumbing .Revision (latestTag .Name ()))
78
+ ref , err := repo .Head ()
79
+
79
80
if err != nil {
80
- log .Fatal ("Error getting the targetted commit for latestTag" )
81
+ log .Fatal ("Unable to get repository HEAD:" , err )
81
82
}
82
- revisionHashPrevious , err := repo .ResolveRevision (plumbing .Revision (previousTag .Name ()))
83
+
84
+ tillLatest := latestTag != nil && latestTag .Hash ().String () != ref .Hash ().String ()
85
+
83
86
if err != nil {
84
- log .Fatal ("Error getting the targetted commit for previousTag" )
87
+ log .Fatal ("Couldn't get latest tag..." , err )
85
88
}
86
89
87
- if err ! = nil {
88
- fmt . Println ( err )
90
+ if latestTag == nil && previousTag = = nil {
91
+ return false
89
92
}
90
93
91
- ref , err := repo .Head ()
94
+ // Ignore errors as these are to be optionally checked
95
+ followedTagReferenceLatest , err := repo .ResolveRevision (plumbing .Revision (latestTag .Name ()))
92
96
93
97
if err != nil {
94
- log .Fatal ("Unable to get repository HEAD:" , err )
98
+ log .Fatal ("Failed to get referenced commit hash for latestTag's revision" )
95
99
}
96
100
97
- tillLatest := latestTag != nil && latestTag . Hash (). String () != ref . Hash (). String ( )
101
+ followedTagReferencePrev , err := repo . ResolveRevision ( plumbing . Revision ( previousTag . Name ()) )
98
102
99
103
if err != nil {
100
- log .Fatal ("Couldn't get latest tag..." , err )
104
+ log .Fatal ("Failed to get referenced commit hash for previous's revision" )
101
105
}
102
106
103
- if latestTag != nil && previousTag != nil {
104
- if tillLatest {
105
- return * revisionHashLatest == commit .Hash
106
- }
107
- return * revisionHashPrevious == commit .Hash
108
-
107
+ if tillLatest {
108
+ return * followedTagReferenceLatest == commit .Hash
109
109
}
110
- return false
110
+
111
+ return * followedTagReferencePrev == commit .Hash
112
+
111
113
}
112
114
113
115
// normalizeCommit - reduces the commit message to the first line and ignore the description text of the commit
0 commit comments