shouldIncludeFile checks if a file passes the only/exclude filters
(relPath string, ext string, only []string, exclude []string)
| 174 | |
| 175 | // shouldIncludeFile checks if a file passes the only/exclude filters |
| 176 | func shouldIncludeFile(relPath string, ext string, only []string, exclude []string) bool { |
| 177 | // If --only specified, file extension must be in the list |
| 178 | if len(only) > 0 { |
| 179 | extNoDot := strings.TrimPrefix(ext, ".") |
| 180 | found := false |
| 181 | for _, o := range only { |
| 182 | o = strings.TrimPrefix(strings.TrimSpace(o), ".") |
| 183 | if strings.EqualFold(extNoDot, o) { |
| 184 | found = true |
| 185 | break |
| 186 | } |
| 187 | } |
| 188 | if !found { |
| 189 | return false |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | // If --exclude specified, check against each pattern |
| 194 | for _, pattern := range exclude { |
| 195 | pattern = strings.TrimSpace(pattern) |
| 196 | if pattern != "" && matchesPattern(relPath, pattern) { |
| 197 | return false |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | return true |
| 202 | } |
| 203 | |
| 204 | // LoadGitignore loads .gitignore from root if it exists |
| 205 | // Deprecated: Use NewGitIgnoreCache for nested gitignore support |