MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / getFilesUsingGit

Function getFilesUsingGit

source code/hooks/fileSuggestions.ts:250–385  ·  view source on GitHub ↗

* Get files using git ls-files (much faster than ripgrep for git repos) * Returns tracked files immediately, fetches untracked in background * @param respectGitignore If true, excludes gitignored files from untracked results * * Note: Unlike ripgrep --follow, git ls-files doesn't follow symlinks

(
  abortSignal: AbortSignal,
  respectGitignore: boolean,
)

Source from the content-addressed store, hash-verified

248 * This is intentional as git tracks symlinks as symlinks.
249 */
250async function getFilesUsingGit(
251 abortSignal: AbortSignal,
252 respectGitignore: boolean,
253): Promise<string[] | null> {
254 const startTime = Date.now()
255 logForDebugging(`[FileIndex] getFilesUsingGit called`)
256
257 // Check if we're in a git repo. findGitRoot is LRU-memoized per path.
258 const repoRoot = findGitRoot(getCwd())
259 if (!repoRoot) {
260 logForDebugging(`[FileIndex] not a git repo, returning null`)
261 return null
262 }
263
264 try {
265 const cwd = getCwd()
266
267 // Get tracked files (fast - reads from git index)
268 // Run from repoRoot so paths are relative to repo root, not CWD
269 const lsFilesStart = Date.now()
270 const trackedResult = await execFileNoThrowWithCwd(
271 gitExe(),
272 ['-c', 'core.quotepath=false', 'ls-files', '--recurse-submodules'],
273 { timeout: 5000, abortSignal, cwd: repoRoot },
274 )
275 logForDebugging(
276 `[FileIndex] git ls-files (tracked) took ${Date.now() - lsFilesStart}ms`,
277 )
278
279 if (trackedResult.code !== 0) {
280 logForDebugging(
281 `[FileIndex] git ls-files failed (code=${trackedResult.code}, stderr=${trackedResult.stderr}), falling back to ripgrep`,
282 )
283 return null
284 }
285
286 const trackedFiles = trackedResult.stdout.trim().split('\n').filter(Boolean)
287
288 // Normalize paths relative to the current working directory
289 let normalizedTracked = normalizeGitPaths(trackedFiles, repoRoot, cwd)
290
291 // Apply .ignore/.rgignore patterns if present (faster than falling back to ripgrep)
292 const ignorePatterns = await loadRipgrepIgnorePatterns(repoRoot, cwd)
293 if (ignorePatterns) {
294 const beforeCount = normalizedTracked.length
295 normalizedTracked = ignorePatterns.filter(normalizedTracked)
296 logForDebugging(
297 `[FileIndex] applied ignore patterns: ${beforeCount} -> ${normalizedTracked.length} files`,
298 )
299 }
300
301 // Cache tracked files for later merge with untracked
302 cachedTrackedFiles = normalizedTracked
303
304 const duration = Date.now() - startTime
305 logForDebugging(
306 `[FileIndex] git ls-files: ${normalizedTracked.length} tracked files in ${duration}ms`,
307 )

Callers 1

getProjectFilesFunction · 0.85

Calls 8

logForDebuggingFunction · 0.85
getCwdFunction · 0.85
execFileNoThrowWithCwdFunction · 0.85
normalizeGitPathsFunction · 0.85
logEventFunction · 0.85
errorMessageFunction · 0.50

Tested by

no test coverage detected