33package commitlog
44
55import (
6- "fmt"
76 "log"
87 "strings"
98
@@ -30,7 +29,7 @@ func GetLatestTagFromRepository(repository *git.Repository) (*plumbing.Reference
3029 var previousTagReturn * plumbing.Reference
3130
3231 err = tagRefs .ForEach (func (tagRef * plumbing.Reference ) error {
33- revision := plumbing .Revision (tagRef .Name (). String () )
32+ revision := plumbing .Revision (tagRef .Name ())
3433
3534 tagCommitHash , err := repository .ResolveRevision (revision )
3635 if err != nil {
@@ -58,6 +57,7 @@ func GetLatestTagFromRepository(repository *git.Repository) (*plumbing.Reference
5857
5958 return nil
6059 })
60+
6161 if err != nil {
6262 return nil , nil , err
6363 }
@@ -75,39 +75,41 @@ func isCommitToNearestTag(repo *git.Repository, commit *object.Commit) bool {
7575 }
7676 }
7777
78- revisionHashLatest , err := repo .ResolveRevision (plumbing .Revision (latestTag .Name ()))
78+ ref , err := repo .Head ()
79+
7980 if err != nil {
80- log .Fatal ("Error getting the targetted commit for latestTag" )
81+ log .Fatal ("Unable to get repository HEAD:" , err )
8182 }
82- revisionHashPrevious , err := repo .ResolveRevision (plumbing .Revision (previousTag .Name ()))
83+
84+ tillLatest := latestTag != nil && latestTag .Hash ().String () != ref .Hash ().String ()
85+
8386 if err != nil {
84- log .Fatal ("Error getting the targetted commit for previousTag" )
87+ log .Fatal ("Couldn't get latest tag..." , err )
8588 }
8689
87- if err ! = nil {
88- fmt . Println ( err )
90+ if latestTag == nil && previousTag = = nil {
91+ return false
8992 }
9093
91- ref , err := repo .Head ()
94+ // Ignore errors as these are to be optionally checked
95+ followedTagReferenceLatest , err := repo .ResolveRevision (plumbing .Revision (latestTag .Name ()))
9296
9397 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" )
9599 }
96100
97- tillLatest := latestTag != nil && latestTag . Hash (). String () != ref . Hash (). String ( )
101+ followedTagReferencePrev , err := repo . ResolveRevision ( plumbing . Revision ( previousTag . Name ()) )
98102
99103 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" )
101105 }
102106
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
109109 }
110- return false
110+
111+ return * followedTagReferencePrev == commit .Hash
112+
111113}
112114
113115// normalizeCommit - reduces the commit message to the first line and ignore the description text of the commit
0 commit comments