| 1 |
// Copyright 2019 The go-git authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
// |
| 15 |
// This file was originally part of https://github.com/go-git/go-git/blob/main/plumbing/format/gitattributes |
| 16 |
// and has been modified to provide a simplified matcher that works with a single pattern. |
| 17 |
|
| 18 |
package gitignore |
| 19 |
|
| 20 |
// Matcher defines a matcher for a single gitignore pattern |
| 21 |
type Matcher struct { |
| 22 |
pattern Pattern |
| 23 |
} |
| 24 |
|
| 25 |
// NewMatcher constructs a new simple matcher for a single pattern |
| 26 |
func NewMatcher(pattern Pattern) *Matcher { |
| 27 |
return &Matcher{pattern: pattern} |
| 28 |
} |
| 29 |
|
| 30 |
// Match matches the given path against the single pattern |
| 31 |
func (m *Matcher) Match(path []string, isDir bool) bool { |
| 32 |
match := m.pattern.Match(path, isDir) |
| 33 |
return match == Exclude |
| 34 |
} |