diff --git a/pkg/git/git.go b/pkg/git/git.go
index 7341c1bc3f04e6d91f17ac877bb523afd5ee19e2..a9c42ce0dd57fd28cb5824cad29dc85988209612 100644
--- a/pkg/git/git.go
+++ b/pkg/git/git.go
@@ -8,6 +8,7 @@ "fmt"
"io"
"io/fs"
"path"
+ "sort"
"time"
"github.com/go-git/go-git/v5"
@@ -26,10 +27,12 @@ type (
GitRepository struct {
path string
repository *git.Repository
-
- ref plumbing.Hash
- // this is setRef when ref is setRef
- setRef bool
+ ref plumbing.Hash
+ setRef bool
+ }
+ TagReference struct {
+ ref *plumbing.Reference
+ tag *object.Tag
}
infoWrapper struct {
name string
@@ -38,10 +41,9 @@ mode fs.FileMode
modTime time.Time
isDir bool
}
-
- TagReference struct {
- ref *plumbing.Reference
- tag *object.Tag
+ tagList struct {
+ refs []*TagReference
+ r *git.Repository
}
)
@@ -151,6 +153,10 @@ return nil
}); err != nil {
return nil, err
}
+
+ // tagList modify the underlying tag list.
+ tagList := &tagList{r: g.repository, refs: tags}
+ sort.Sort(tagList)
return tags, nil
}
@@ -395,3 +401,40 @@ }
return ""
}
+
+func (self *tagList) Len() int {
+ return len(self.refs)
+}
+
+func (self *tagList) Swap(i, j int) {
+ self.refs[i], self.refs[j] = self.refs[j], self.refs[i]
+}
+
+func (self *tagList) Less(i, j int) bool {
+ var dateI time.Time
+ var dateJ time.Time
+
+ if self.refs[i].tag != nil {
+ dateI = self.refs[i].tag.Tagger.When
+ } else {
+ c, err := self.r.CommitObject(self.refs[i].ref.Hash())
+ if err != nil {
+ dateI = time.Now()
+ } else {
+ dateI = c.Committer.When
+ }
+ }
+
+ if self.refs[j].tag != nil {
+ dateJ = self.refs[j].tag.Tagger.When
+ } else {
+ c, err := self.r.CommitObject(self.refs[j].ref.Hash())
+ if err != nil {
+ dateJ = time.Now()
+ } else {
+ dateJ = c.Committer.When
+ }
+ }
+
+ return dateI.After(dateJ)
+}