From 2edc9392455262baf0e20f04ad996498c2bac095 Mon Sep 17 00:00:00 2001 From: Colby McHenry Date: Fri, 3 Apr 2026 17:17:31 -0500 Subject: [PATCH] fix: Handle gitignored project directories in git file detection When a project directory is gitignored by a parent git repository, `git ls-files` returns no results even though files exist. Added detection for this scenario using `git rev-parse` and `git check-ignore` to fall back to filesystem walking when the project directory is ignored by an ancestor repo. --- src/extraction/index.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/extraction/index.ts b/src/extraction/index.ts index b009cf0..2142331 100644 --- a/src/extraction/index.ts +++ b/src/extraction/index.ts @@ -111,6 +111,30 @@ export function shouldIncludeFile( */ function getGitVisibleFiles(rootDir: string): Set | null { try { + // Check if the project directory is gitignored by a parent repo. + // When rootDir lives inside a parent git repo that ignores it, + // `git ls-files` returns nothing — fall back to filesystem walk. + const gitRoot = execFileSync( + 'git', + ['rev-parse', '--show-toplevel'], + { cwd: rootDir, encoding: 'utf-8', timeout: 5000, stdio: ['pipe', 'pipe', 'pipe'] } + ).trim(); + + if (path.resolve(gitRoot) !== path.resolve(rootDir)) { + try { + // git check-ignore exits 0 if the path IS ignored, 1 if not + execFileSync( + 'git', + ['check-ignore', '-q', path.resolve(rootDir)], + { cwd: rootDir, encoding: 'utf-8', timeout: 5000, stdio: ['pipe', 'pipe', 'pipe'] } + ); + // Directory is gitignored by parent repo — fall back to filesystem walk + return null; + } catch { + // Not ignored — safe to use git ls-files + } + } + // -c = cached (tracked), -o = others (untracked), --exclude-standard = respect .gitignore const output = execFileSync( 'git',