44 "fmt"
55 "io/ioutil"
66 "os"
7+ "regexp"
78 "strconv"
89 "strings"
910 "time"
@@ -53,6 +54,62 @@ func (g *GitHandler) IsUpToDate() bool {
5354 return time .Now ().Unix () <= (g .GetUpdatedTime () + int64 (g .Cfg .Git .Update .Cache .Time ))
5455}
5556
57+ func (g * GitHandler ) filterBranches (references []string ) []string {
58+ filters := g .Cfg .Display .Branches .Filter
59+ if len (filters ) == 0 {
60+ return references
61+ }
62+ var output []string
63+ for _ , v := range references {
64+ valid := false
65+ for _ , f := range filters {
66+ if strings .HasPrefix (f , "/" ) && strings .HasSuffix (f , "/" ) {
67+ // RegEx
68+ expression := strings .Trim (f , "/" )
69+ valid = regexp .MustCompile (expression ).MatchString (v )
70+ } else {
71+ valid = f == v
72+ }
73+ if valid {
74+ break
75+ }
76+ }
77+ if ! valid {
78+ continue
79+ }
80+ output = append (output , v )
81+ }
82+ return output
83+ }
84+
85+ func (g * GitHandler ) filterTags (references []GitTag ) []GitTag {
86+ filters := g .Cfg .Display .Tags .Filter
87+ if len (filters ) == 0 {
88+ return references
89+ }
90+ var output []GitTag
91+ for _ , v := range references {
92+ valid := false
93+ for _ , f := range filters {
94+ if strings .HasPrefix (f , "/" ) && strings .HasSuffix (f , "/" ) {
95+ // RegEx
96+ expression := strings .Trim (f , "/" )
97+ valid = regexp .MustCompile (expression ).MatchString (v .Tag )
98+ } else {
99+ valid = f == v .Tag
100+ }
101+ if valid {
102+ break
103+ }
104+ }
105+ if ! valid {
106+ continue
107+ }
108+ output = append (output , v )
109+ }
110+ return output
111+ }
112+
56113func (g * GitHandler ) GetBranches () []string {
57114 output , _ := g .runGitCommand ("branch" , "-l" , "-r" , "--no-color" )
58115 var branches []string
@@ -61,7 +118,7 @@ func (g *GitHandler) GetBranches() []string {
61118 v = strings .TrimPrefix (v , "origin/" )
62119 branches = append (branches , v )
63120 }
64- return branches
121+ return g . filterBranches ( branches )
65122}
66123
67124type GitTag struct {
@@ -83,5 +140,6 @@ func (g *GitHandler) GetTags() []GitTag {
83140 Date : intDate ,
84141 })
85142 }
86- return tags
143+
144+ return g .filterTags (tags )
87145}
0 commit comments