@@ -143,6 +143,10 @@ func (r *Repository) Tag(name string, opts ...TagOptions) (*Tag, error) {
143143//
144144// Docs: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---list
145145type TagsOptions struct {
146+ // SortKet sorts tags with provided tag key, optionally prefixed with '-' to sort tags in descending order.
147+ SortKey string
148+ // Pattern filters tags matching the specified pattern.
149+ Pattern string
146150 // The timeout duration before giving up for each shell command execution. The
147151 // default timeout duration will be used when not supplied.
148152 Timeout time.Duration
@@ -161,8 +165,18 @@ func RepoTags(repoPath string, opts ...TagsOptions) ([]string, error) {
161165 }
162166
163167 cmd := NewCommand ("tag" , "--list" )
164- if goversion .Compare (version , "2.4.9" , ">=" ) {
168+
169+ var sorted bool
170+ if opt .SortKey != "" {
171+ cmd .AddArgs ("--sort=" + opt .SortKey )
172+ sorted = true
173+ } else if goversion .Compare (version , "2.4.9" , ">=" ) {
165174 cmd .AddArgs ("--sort=-creatordate" )
175+ sorted = true
176+ }
177+
178+ if opt .Pattern != "" {
179+ cmd .AddArgs (opt .Pattern )
166180 }
167181
168182 stdout , err := cmd .RunInDirWithTimeout (opt .Timeout , repoPath )
@@ -173,7 +187,7 @@ func RepoTags(repoPath string, opts ...TagsOptions) ([]string, error) {
173187 tags := strings .Split (string (stdout ), "\n " )
174188 tags = tags [:len (tags )- 1 ]
175189
176- if goversion . Compare ( version , "2.4.9" , "<" ) {
190+ if ! sorted {
177191 goversion .Sort (tags )
178192
179193 // Reverse order
0 commit comments