MCPcopy Create free account
hub / github.com/JordanCoin/codemap / ShouldIgnore

Method ShouldIgnore

scanner/walker.go:77–107  ·  view source on GitHub ↗

ShouldIgnore checks if a path should be ignored based on all applicable .gitignore files. Git evaluates rules from root to leaf, with later rules overriding earlier ones.

(absPath string)

Source from the content-addressed store, hash-verified

75// ShouldIgnore checks if a path should be ignored based on all applicable .gitignore files.
76// Git evaluates rules from root to leaf, with later rules overriding earlier ones.
77func (c *GitIgnoreCache) ShouldIgnore(absPath string) bool {
78 if len(c.cache) == 0 {
79 return false
80 }
81
82 // Collect directories from leaf to root
83 var dirs []string
84 for dir := filepath.Dir(absPath); ; dir = filepath.Dir(dir) {
85 dirs = append(dirs, dir)
86 if dir == c.root || dir == filepath.Dir(dir) {
87 break
88 }
89 }
90
91 // Combine all patterns from root to leaf into one gitignore.
92 // This allows negation patterns in child .gitignore to override parent rules.
93 var allPatterns []string
94 for i := len(dirs) - 1; i >= 0; i-- {
95 if patterns, ok := c.patterns[dirs[i]]; ok {
96 allPatterns = append(allPatterns, patterns...)
97 }
98 }
99
100 if len(allPatterns) == 0 {
101 return false
102 }
103
104 combined := ignore.CompileIgnoreLines(allPatterns...)
105 relPath, _ := filepath.Rel(c.root, absPath)
106 return combined.MatchesPath(relPath)
107}
108
109// IgnoredDirs are directories to skip during scanning
110var IgnoredDirs = map[string]bool{

Callers 4

addWatchDirsMethod · 0.80
handleEventMethod · 0.80
ScanFilesFunction · 0.80

Calls

no outgoing calls

Tested by 1