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

Method isPathExcluded

internal/diff/git.go:264–294  ·  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

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

Callers 3

filterDiffsMethod · 0.95
untrackedFilesListMethod · 0.95
IsPathExcludedFunction · 0.95

Calls 1

matchGitignoreBodyFunction · 0.85

Tested by

no test coverage detected