MCPcopy Create free account
hub / github.com/go-task/task / globMatch

Method globMatch

internal/gitignore/pattern.go:117–165  ·  view source on GitHub ↗
(path []string, isDir bool)

Source from the content-addressed store, hash-verified

115}
116
117func (p *pattern) globMatch(path []string, isDir bool) bool {
118 matched := false
119 canTraverse := false
120 for i, pattern := range p.pattern {
121 if pattern == "" {
122 canTraverse = false
123 continue
124 }
125 if pattern == zeroToManyDirs {
126 if i == len(p.pattern)-1 {
127 break
128 }
129 canTraverse = true
130 continue
131 }
132 if strings.Contains(pattern, zeroToManyDirs) {
133 return false
134 }
135 if len(path) == 0 {
136 return false
137 }
138 if canTraverse {
139 canTraverse = false
140 for len(path) > 0 {
141 e := path[0]
142 path = path[1:]
143 if match, err := filepath.Match(pattern, e); err != nil {
144 return false
145 } else if match {
146 matched = true
147 break
148 } else if len(path) == 0 {
149 // if nothing left then fail
150 matched = false
151 }
152 }
153 } else {
154 if match, err := filepath.Match(pattern, path[0]); err != nil || !match {
155 return false
156 }
157 matched = true
158 path = path[1:]
159 }
160 }
161 if matched && p.dirOnly && !isDir && len(path) == 0 {
162 matched = false
163 }
164 return matched
165}

Callers 1

MatchMethod · 0.95

Calls 1

MatchMethod · 0.65

Tested by

no test coverage detected