MCPcopy Create free account
hub / github.com/go-git/go-git / Match

Method Match

plumbing/format/gitattributes/pattern.go:33–106  ·  view source on GitHub ↗
(path []string)

Source from the content-addressed store, hash-verified

31}
32
33func (p *pattern) Match(path []string) bool {
34 if len(path) <= len(p.domain) {
35 return false
36 }
37 for i, e := range p.domain {
38 if path[i] != e {
39 return false
40 }
41 }
42
43 if len(p.pattern) == 1 {
44 // for a simple rule, .gitattribute matching rules differs from
45 // .gitignore and only the last part of the path is considered.
46 path = path[len(path)-1:]
47 } else {
48 path = path[len(p.domain):]
49 }
50
51 pattern := p.pattern
52 var match, doublestar bool
53 var err error
54 for _, part := range path {
55 // path is deeper than pattern
56 if len(pattern) == 0 {
57 return false
58 }
59
60 // skip empty
61 if pattern[0] == "" {
62 pattern = pattern[1:]
63 }
64
65 // eat doublestar
66 if pattern[0] == zeroToManyDirs {
67 pattern = pattern[1:]
68 if len(pattern) == 0 {
69 return true
70 }
71 doublestar = true
72 }
73
74 switch {
75 case strings.Contains(pattern[0], "**"):
76 return false
77
78 // keep going down the path until we hit a match
79 case doublestar:
80 match, err = filepath.Match(pattern[0], part)
81 if err != nil {
82 return false
83 }
84
85 if match {
86 doublestar = false
87 pattern = pattern[1:]
88 }
89
90 default:

Callers

nothing calls this directly

Calls 2

ContainsMethod · 0.65
MatchMethod · 0.65

Tested by

no test coverage detected