Add .geminiignore support to the glob tool. (#8086)

This commit is contained in:
Tommaso Sciortino
2025-09-10 09:54:50 -07:00
committed by GitHub
parent ef70c17936
commit 0e3a0d7dc5
6 changed files with 388 additions and 470 deletions
@@ -16,6 +16,12 @@ export interface FilterFilesOptions {
respectGeminiIgnore?: boolean;
}
export interface FilterReport {
filteredPaths: string[];
gitIgnoredCount: number;
geminiIgnoredCount: number;
}
export class FileDiscoveryService {
private gitIgnoreFilter: GitIgnoreFilter | null = null;
private geminiIgnoreFilter: GitIgnoreFilter | null = null;
@@ -65,6 +71,42 @@ export class FileDiscoveryService {
});
}
/**
* Filters a list of file paths based on git ignore rules and returns a report
* with counts of ignored files.
*/
filterFilesWithReport(
filePaths: string[],
opts: FilterFilesOptions = {
respectGitIgnore: true,
respectGeminiIgnore: true,
},
): FilterReport {
const filteredPaths: string[] = [];
let gitIgnoredCount = 0;
let geminiIgnoredCount = 0;
for (const filePath of filePaths) {
if (opts.respectGitIgnore && this.shouldGitIgnoreFile(filePath)) {
gitIgnoredCount++;
continue;
}
if (opts.respectGeminiIgnore && this.shouldGeminiIgnoreFile(filePath)) {
geminiIgnoredCount++;
continue;
}
filteredPaths.push(filePath);
}
return {
filteredPaths,
gitIgnoredCount,
geminiIgnoredCount,
};
}
/**
* Checks if a single file should be git-ignored
*/