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

Method isPathExcluded

internal/diff/git.go:258–288  ·  view source on GitHub ↗

isPathExcluded returns true when the given relative file path should be skipped based on hardcoded dir rules or .gitignore patterns. Patterns are resolved the way git resolves them: in file order, with the LAST matching pattern deciding, and a leading "!" inverting that pattern's verdict. Order mat

(relPath string, gitignorePatterns []string)

Source from the content-addressed store, hash-verified

256// correct under last-match-wins. Treating negations as unmatchable made every
257// file in such a repository look excluded, so a review silently covered nothing.
258func (p *Provider) isPathExcluded(relPath string, gitignorePatterns []string) bool {
259 // Hardcoded directory prefix checks. These are an unconditional blocklist:
260 // a .gitignore negation cannot re-admit .git/ or node_modules/.
261 for _, prefix := range providerDirIgnoreDirs {
262 dirPart := strings.TrimSuffix(prefix, "/")
263 if relPath == dirPart || strings.HasPrefix(relPath, prefix) {
264 return true
265 }
266 }
267
268 excluded := false
269 for _, pat := range gitignorePatterns {
270 body, negated := strings.CutPrefix(pat, "!")
271 if body == "" {
272 continue
273 }
274
275 // Directory-only patterns (trailing "/") apply to directories, never to
276 // files. Git uses a negated one such as `!*/` to keep descending into
277 // subdirectories, not to re-admit the files inside them — honouring it
278 // here would readmit everything below the root.
279 if negated && strings.HasSuffix(body, "/") {
280 continue
281 }
282
283 if matchGitignoreBody(relPath, body) {
284 excluded = !negated
285 }
286 }
287 return excluded
288}
289
290// matchGitignorePattern checks if relPath matches a single .gitignore pattern.
291//

Callers 3

filterDiffsMethod · 0.95
untrackedFilesListMethod · 0.95
IsPathExcludedFunction · 0.95

Calls 1

matchGitignoreBodyFunction · 0.85

Tested by

no test coverage detected