11package gitw
22
33import (
4- "fmt"
54 "strings"
65
76 "github.com/gookit/goutil/arrutil"
@@ -18,11 +17,6 @@ const (
1817 cacheMaxTagVersion = "maxVersion"
1918)
2019
21- // CmdBuilder struct
22- // type CmdBuilder struct {
23- // Dir string
24- // }
25-
2620// RepoConfig struct
2721type RepoConfig struct {
2822 DefaultBranch string
@@ -131,20 +125,20 @@ const (
131125 TagHead = "head"
132126)
133127
134- // type value constants for fetch tags
128+ // enum type value constants for fetch tags
135129const (
136- RefnameTagType int = iota
137- CreatordateTagType
130+ RefNameTagType int = iota
131+ CreatorDateTagType
138132 DescribeTagType
139133)
140134
141135// AutoMatchTag by given sha or tag name
142136func (r * Repo ) AutoMatchTag (sha string ) string {
143- return r .AutoMatchTagByTagType (sha , RefnameTagType )
137+ return r .AutoMatchTagByType (sha , RefNameTagType )
144138}
145139
146- // AutoMatchTagByTagType by given sha or tag name
147- func (r * Repo ) AutoMatchTagByTagType (sha string , tagType int ) string {
140+ // AutoMatchTagByType by given sha or tag name.
141+ func (r * Repo ) AutoMatchTagByType (sha string , tagType int ) string {
148142 switch strings .ToLower (sha ) {
149143 case TagLast :
150144 return r .LargestTagByTagType (tagType )
@@ -187,8 +181,8 @@ func (r *Repo) LargestTagByTagType(tagType int) string {
187181
188182 tags := make ([]string , 0 , 2 )
189183 switch tagType {
190- case CreatordateTagType :
191- tags = append (tags , r .TagsSortedByCreatordate ()... )
184+ case CreatorDateTagType :
185+ tags = append (tags , r .TagsSortedByCreatorDate ()... )
192186 case DescribeTagType :
193187 tags = append (tags , r .TagByDescribe ("" ))
194188 default :
@@ -221,8 +215,8 @@ func (r *Repo) TagSecondMax() string {
221215func (r * Repo ) TagSecondMaxByTagType (tagType int ) string {
222216 tags := make ([]string , 0 , 2 )
223217 switch tagType {
224- case CreatordateTagType :
225- tags = append (tags , r .TagsSortedByCreatordate ()... )
218+ case CreatorDateTagType :
219+ tags = append (tags , r .TagsSortedByCreatorDate ()... )
226220 case DescribeTagType :
227221 current := r .TagByDescribe ("" )
228222 if len (current ) != 0 {
@@ -251,30 +245,36 @@ func (r *Repo) TagsSortedByRefName() []string {
251245 return OutputLines (str )
252246}
253247
254- // TagsSortedByCreatordate get repo tags list by creatordate sort
255- func (r * Repo ) TagsSortedByCreatordate () []string {
256- str , err := r .gw .Tag ("-l" , "--sort=-creatordate" , "--format=\" %(refname:strip=2)\" " ).Output ()
248+ // TagsSortedByCreatorDate get repo tags list by creator date sort
249+ func (r * Repo ) TagsSortedByCreatorDate () []string {
250+ str , err := r .gw .
251+ Tag ("-l" , "--sort=-creatordate" , "--format=%(refname:strip=2)" ).
252+ Output ()
253+
257254 if err != nil {
258255 r .setErr (err )
259256 return nil
260257 }
261258 return OutputLines (str )
262259}
263260
264- // TagByDescribe get tag by describe command
265- func (r * Repo ) TagByDescribe (current string ) (str string ) {
261+ // TagByDescribe get tag by describe command. if current not empty, will exclude it.
262+ func (r * Repo ) TagByDescribe (current string ) (ver string ) {
266263 var err error
267264 if len (current ) == 0 {
268- str , err = r .gw .Describe ("--tags" , "--abbrev=0" ).Output ()
265+ ver , err = r .gw .Describe ("--tags" , "--abbrev=0" ).Output ()
269266 } else {
270- str , err = r .gw .Describe ("--tags" , "--abbrev=0" , fmt .Sprintf ("tags/%s^" , current )).Output ()
267+ ver , err = r .gw .
268+ Describe ("--tags" , "--abbrev=0" ).
269+ Argf ("tags/%s^" , current ).
270+ Output ()
271271 }
272272
273273 if err != nil {
274274 r .setErr (err )
275275 return ""
276276 }
277- return FirstLine (str )
277+ return FirstLine (ver )
278278}
279279
280280// Tags get repo tags list
0 commit comments