@@ -144,6 +144,10 @@ type TagsOptions struct {
144
144
// The timeout duration before giving up for each shell command execution.
145
145
// The default timeout duration will be used when not supplied.
146
146
Timeout time.Duration
147
+ // SortKet sorts tags with provided tag key, optionally prefixed with '-' to sort tags in descending order.
148
+ SortKey string
149
+ // Pattern filters tags matching the specified pattern.
150
+ Pattern string
147
151
}
148
152
149
153
// RepoTags returns a list of tags of the repository in given path.
@@ -159,8 +163,18 @@ func RepoTags(repoPath string, opts ...TagsOptions) ([]string, error) {
159
163
}
160
164
161
165
cmd := NewCommand ("tag" , "--list" )
162
- if goversion .Compare (version , "2.4.9" , ">=" ) {
166
+
167
+ var sorted bool
168
+ if opt .SortKey != "" {
169
+ cmd .AddArgs (fmt .Sprintf ("--sort=%s" , opt .SortKey ))
170
+ sorted = true
171
+ } else if goversion .Compare (version , "2.4.9" , ">=" ) {
163
172
cmd .AddArgs ("--sort=-creatordate" )
173
+ sorted = true
174
+ }
175
+
176
+ if opt .Pattern != "" {
177
+ cmd .AddArgs (opt .Pattern )
164
178
}
165
179
166
180
stdout , err := cmd .RunInDirWithTimeout (opt .Timeout , repoPath )
@@ -171,7 +185,7 @@ func RepoTags(repoPath string, opts ...TagsOptions) ([]string, error) {
171
185
tags := strings .Split (string (stdout ), "\n " )
172
186
tags = tags [:len (tags )- 1 ]
173
187
174
- if goversion . Compare ( version , "2.4.9" , "<" ) {
188
+ if ! sorted {
175
189
goversion .Sort (tags )
176
190
177
191
// Reverse order
0 commit comments