@@ -143,6 +143,10 @@ func (r *Repository) Tag(name string, opts ...TagOptions) (*Tag, error) {
143
143
//
144
144
// Docs: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---list
145
145
type 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
146
150
// The timeout duration before giving up for each shell command execution. The
147
151
// default timeout duration will be used when not supplied.
148
152
Timeout time.Duration
@@ -161,8 +165,18 @@ func RepoTags(repoPath string, opts ...TagsOptions) ([]string, error) {
161
165
}
162
166
163
167
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" , ">=" ) {
165
174
cmd .AddArgs ("--sort=-creatordate" )
175
+ sorted = true
176
+ }
177
+
178
+ if opt .Pattern != "" {
179
+ cmd .AddArgs (opt .Pattern )
166
180
}
167
181
168
182
stdout , err := cmd .RunInDirWithTimeout (opt .Timeout , repoPath )
@@ -173,7 +187,7 @@ func RepoTags(repoPath string, opts ...TagsOptions) ([]string, error) {
173
187
tags := strings .Split (string (stdout ), "\n " )
174
188
tags = tags [:len (tags )- 1 ]
175
189
176
- if goversion . Compare ( version , "2.4.9" , "<" ) {
190
+ if ! sorted {
177
191
goversion .Sort (tags )
178
192
179
193
// Reverse order
0 commit comments