MCPcopy Create free account
hub / github.com/alibaba/open-code-review / matchGitignorePattern

Function matchGitignorePattern

internal/diff/git.go:206–239  ·  view source on GitHub ↗

matchGitignorePattern checks if relPath matches a single .gitignore pattern.

(relPath, pat string)

Source from the content-addressed store, hash-verified

204
205// matchGitignorePattern checks if relPath matches a single .gitignore pattern.
206func matchGitignorePattern(relPath, pat string) bool {
207 // Directory-only patterns (trailing /)
208 if before, ok := strings.CutSuffix(pat, "/"); ok {
209 dirName := before
210 // Match if any path segment equals the dir name
211 segments := strings.Split(relPath, "/")
212 return slices.Contains(segments, dirName)
213 }
214
215 // Negation patterns are not needed for exclusion purposes
216 if strings.HasPrefix(pat, "!") {
217 return false
218 }
219
220 // Patterns without / match basename
221 if !strings.Contains(pat, "/") {
222 base := filepath.Base(relPath)
223 if matched, _ := filepath.Match(pat, base); matched {
224 return true
225 }
226 return false
227 }
228
229 // Patterns with / match against the full relative path
230 if matched, _ := filepath.Match(pat, relPath); matched {
231 return true
232 }
233 // Also try matching against suffix of path
234 if strings.HasSuffix(relPath, pat) {
235 return true
236 }
237
238 return false
239}
240
241// filterDiffs removes diffs whose file paths are excluded.
242func (p *Provider) filterDiffs(diffs []model.Diff) []model.Diff {

Callers 2

isPathExcludedMethod · 0.85
MatchGitignorePatternFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected