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

Function parseGitignore

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

Source from the content-addressed store, hash-verified

190}
191
192export async function parseGitignore(params: {
193 fullDirPath: string
194 projectRoot: string
195 fs: CodebuffFileSystem
196}): Promise<ignore.Ignore> {
197 const { fullDirPath, projectRoot, fs } = params
198
199 const ig = ignore.default()
200 const relativeDirPath = path.relative(projectRoot, fullDirPath)
201 const ignoreFiles = [
202 path.join(fullDirPath, '.gitignore'),
203 path.join(fullDirPath, '.codebuffignore'),
204 path.join(fullDirPath, '.manicodeignore'), // Legacy support
205 ]
206
207 for (const ignoreFilePath of ignoreFiles) {
208 const ignoreFileExists = await fileExists({ filePath: ignoreFilePath, fs })
209 if (!ignoreFileExists) continue
210
211 let ignoreContent: string
212 try {
213 ignoreContent = await fs.readFile(ignoreFilePath, 'utf8')
214 } catch (error: unknown) {
215 // Ignore file may be inaccessible or deleted after existence check.
216 // Log with context for debugging, but continue without these ignore rules.
217 logFileTreeError('fs.readFile (ignore file)', ignoreFilePath, error)
218 continue
219 }
220 const lines = ignoreContent.split('\n')
221 for (let line of lines) {
222 line = line.trim()
223 if (line === '' || line.startsWith('#')) continue
224
225 const finalPattern = rebaseGitignorePattern(line, relativeDirPath)
226
227 ig.add(finalPattern)
228 }
229 }
230
231 return ig
232}
233
234export function getAllFilePaths(
235 nodes: FileTreeNode[],

Callers 2

getProjectFileTreeFunction · 0.85
isFileIgnoredFunction · 0.85

Calls 4

fileExistsFunction · 0.90
logFileTreeErrorFunction · 0.85
rebaseGitignorePatternFunction · 0.85
readFileMethod · 0.80

Tested by

no test coverage detected