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

Method isPathExcluded

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

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

Callers 3

filterDiffsMethod · 0.95
untrackedFilesListMethod · 0.95
IsPathExcludedFunction · 0.95

Calls 1

matchGitignoreBodyFunction · 0.85

Tested by

no test coverage detected