fix: gitignore handling (#8177)

This commit is contained in:
Gaurav
2025-09-10 12:48:07 -07:00
committed by GitHub
parent 32abe905f1
commit db99fc70b6
5 changed files with 251 additions and 164 deletions

View File

@@ -5,12 +5,12 @@
*/
import type { GitIgnoreFilter } from '../utils/gitIgnoreParser.js';
import type { GeminiIgnoreFilter } from '../utils/geminiIgnoreParser.js';
import { GitIgnoreParser } from '../utils/gitIgnoreParser.js';
import { GeminiIgnoreParser } from '../utils/geminiIgnoreParser.js';
import { isGitRepository } from '../utils/gitUtils.js';
import * as path from 'node:path';
const GEMINI_IGNORE_FILE_NAME = '.geminiignore';
export interface FilterFilesOptions {
respectGitIgnore?: boolean;
respectGeminiIgnore?: boolean;
@@ -24,27 +24,15 @@ export interface FilterReport {
export class FileDiscoveryService {
private gitIgnoreFilter: GitIgnoreFilter | null = null;
private geminiIgnoreFilter: GitIgnoreFilter | null = null;
private geminiIgnoreFilter: GeminiIgnoreFilter | null = null;
private projectRoot: string;
constructor(projectRoot: string) {
this.projectRoot = path.resolve(projectRoot);
if (isGitRepository(this.projectRoot)) {
const parser = new GitIgnoreParser(this.projectRoot);
try {
parser.loadGitRepoPatterns();
} catch (_error) {
// ignore file not found
}
this.gitIgnoreFilter = parser;
this.gitIgnoreFilter = new GitIgnoreParser(this.projectRoot);
}
const gParser = new GitIgnoreParser(this.projectRoot);
try {
gParser.loadPatterns(GEMINI_IGNORE_FILE_NAME);
} catch (_error) {
// ignore file not found
}
this.geminiIgnoreFilter = gParser;
this.geminiIgnoreFilter = new GeminiIgnoreParser(this.projectRoot);
}
/**