MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / isFileIgnored

Function isFileIgnored

common/src/project-file-tree.ts:289–318  ·  view source on GitHub ↗
(params: {
  filePath: string
  projectRoot: string
  fs: CodebuffFileSystem
})

Source from the content-addressed store, hash-verified

287}
288
289export async function isFileIgnored(params: {
290 filePath: string
291 projectRoot: string
292 fs: CodebuffFileSystem
293}): Promise<boolean> {
294 const { filePath, projectRoot, fs } = params
295
296 const defaultIgnore = ignore.default()
297 for (const pattern of DEFAULT_IGNORED_PATHS) {
298 defaultIgnore.add(pattern)
299 }
300
301 const relativeFilePath = path.relative(
302 projectRoot,
303 path.join(projectRoot, filePath),
304 )
305 const dirPath = path.dirname(path.join(projectRoot, filePath))
306
307 // Get ignore patterns from the directory containing the file and all parent directories
308 const mergedIgnore = ignore.default().add(defaultIgnore)
309 let currentDir = dirPath
310 while (currentDir.startsWith(projectRoot)) {
311 mergedIgnore.add(
312 await parseGitignore({ fullDirPath: currentDir, projectRoot, fs }),
313 )
314 currentDir = path.dirname(currentDir)
315 }
316
317 return mergedIgnore.ignores(relativeFilePath)
318}

Callers 1

getFilesFunction · 0.90

Calls 1

parseGitignoreFunction · 0.85

Tested by

no test coverage detected