mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-12 22:31:12 -07:00
refactor: simplify FilterReport and remove unused code (#11681)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
@@ -136,6 +136,43 @@ describe('FileDiscoveryService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('filterFilesWithReport', () => {
|
||||
beforeEach(async () => {
|
||||
await fs.mkdir(path.join(projectRoot, '.git'));
|
||||
await createTestFile('.gitignore', 'node_modules/');
|
||||
await createTestFile('.geminiignore', '*.log');
|
||||
});
|
||||
|
||||
it('should return filtered paths and correct ignored count', () => {
|
||||
const files = [
|
||||
'src/index.ts',
|
||||
'node_modules/package/index.js',
|
||||
'debug.log',
|
||||
'README.md',
|
||||
].map((f) => path.join(projectRoot, f));
|
||||
|
||||
const service = new FileDiscoveryService(projectRoot);
|
||||
const report = service.filterFilesWithReport(files);
|
||||
|
||||
expect(report.filteredPaths).toEqual(
|
||||
['src/index.ts', 'README.md'].map((f) => path.join(projectRoot, f)),
|
||||
);
|
||||
expect(report.ignoredCount).toBe(2);
|
||||
});
|
||||
|
||||
it('should handle no ignored files', () => {
|
||||
const files = ['src/index.ts', 'README.md'].map((f) =>
|
||||
path.join(projectRoot, f),
|
||||
);
|
||||
|
||||
const service = new FileDiscoveryService(projectRoot);
|
||||
const report = service.filterFilesWithReport(files);
|
||||
|
||||
expect(report.filteredPaths).toEqual(files);
|
||||
expect(report.ignoredCount).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('shouldGitIgnoreFile & shouldGeminiIgnoreFile', () => {
|
||||
beforeEach(async () => {
|
||||
await fs.mkdir(path.join(projectRoot, '.git'));
|
||||
|
||||
@@ -18,8 +18,7 @@ export interface FilterFilesOptions {
|
||||
|
||||
export interface FilterReport {
|
||||
filteredPaths: string[];
|
||||
gitIgnoredCount: number;
|
||||
geminiIgnoredCount: number;
|
||||
ignoredCount: number;
|
||||
}
|
||||
|
||||
export class FileDiscoveryService {
|
||||
@@ -70,28 +69,12 @@ export class FileDiscoveryService {
|
||||
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);
|
||||
}
|
||||
const filteredPaths = this.filterFiles(filePaths, opts);
|
||||
const ignoredCount = filePaths.length - filteredPaths.length;
|
||||
|
||||
return {
|
||||
filteredPaths,
|
||||
gitIgnoredCount,
|
||||
geminiIgnoredCount,
|
||||
ignoredCount,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user