mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-12 15:10:59 -07:00
fix(core): Add .geminiignore support to SearchText tool (#13763)
Co-authored-by: Gaurav <39389231+gsquared94@users.noreply.github.com>
This commit is contained in:
@@ -58,6 +58,25 @@ describe('GeminiIgnoreParser', () => {
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return ignore file path when patterns exist', () => {
|
||||
const parser = new GeminiIgnoreParser(projectRoot);
|
||||
expect(parser.getIgnoreFilePath()).toBe(
|
||||
path.join(projectRoot, '.geminiignore'),
|
||||
);
|
||||
});
|
||||
|
||||
it('should return true for hasPatterns when patterns exist', () => {
|
||||
const parser = new GeminiIgnoreParser(projectRoot);
|
||||
expect(parser.hasPatterns()).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for hasPatterns when .geminiignore is deleted', async () => {
|
||||
const parser = new GeminiIgnoreParser(projectRoot);
|
||||
await fs.rm(path.join(projectRoot, '.geminiignore'));
|
||||
expect(parser.hasPatterns()).toBe(false);
|
||||
expect(parser.getIgnoreFilePath()).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when .geminiignore does not exist', () => {
|
||||
@@ -66,5 +85,50 @@ describe('GeminiIgnoreParser', () => {
|
||||
expect(parser.getPatterns()).toEqual([]);
|
||||
expect(parser.isIgnored('any_file.txt')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return null for getIgnoreFilePath when no patterns exist', () => {
|
||||
const parser = new GeminiIgnoreParser(projectRoot);
|
||||
expect(parser.getIgnoreFilePath()).toBeNull();
|
||||
});
|
||||
|
||||
it('should return false for hasPatterns when no patterns exist', () => {
|
||||
const parser = new GeminiIgnoreParser(projectRoot);
|
||||
expect(parser.hasPatterns()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when .geminiignore is empty', () => {
|
||||
beforeEach(async () => {
|
||||
await createTestFile('.geminiignore', '');
|
||||
});
|
||||
|
||||
it('should return null for getIgnoreFilePath', () => {
|
||||
const parser = new GeminiIgnoreParser(projectRoot);
|
||||
expect(parser.getIgnoreFilePath()).toBeNull();
|
||||
});
|
||||
|
||||
it('should return false for hasPatterns', () => {
|
||||
const parser = new GeminiIgnoreParser(projectRoot);
|
||||
expect(parser.hasPatterns()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when .geminiignore only has comments', () => {
|
||||
beforeEach(async () => {
|
||||
await createTestFile(
|
||||
'.geminiignore',
|
||||
'# This is a comment\n# Another comment\n',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return null for getIgnoreFilePath', () => {
|
||||
const parser = new GeminiIgnoreParser(projectRoot);
|
||||
expect(parser.getIgnoreFilePath()).toBeNull();
|
||||
});
|
||||
|
||||
it('should return false for hasPatterns', () => {
|
||||
const parser = new GeminiIgnoreParser(projectRoot);
|
||||
expect(parser.hasPatterns()).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,6 +11,8 @@ import ignore from 'ignore';
|
||||
export interface GeminiIgnoreFilter {
|
||||
isIgnored(filePath: string): boolean;
|
||||
getPatterns(): string[];
|
||||
getIgnoreFilePath(): string | null;
|
||||
hasPatterns(): boolean;
|
||||
}
|
||||
|
||||
export class GeminiIgnoreParser implements GeminiIgnoreFilter {
|
||||
@@ -78,4 +80,26 @@ export class GeminiIgnoreParser implements GeminiIgnoreFilter {
|
||||
getPatterns(): string[] {
|
||||
return this.patterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to .geminiignore file if it exists and has patterns.
|
||||
* Useful for tools like ripgrep that support --ignore-file flag.
|
||||
*/
|
||||
getIgnoreFilePath(): string | null {
|
||||
if (!this.hasPatterns()) {
|
||||
return null;
|
||||
}
|
||||
return path.join(this.projectRoot, '.geminiignore');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if .geminiignore exists and has patterns.
|
||||
*/
|
||||
hasPatterns(): boolean {
|
||||
if (this.patterns.length === 0) {
|
||||
return false;
|
||||
}
|
||||
const ignoreFilePath = path.join(this.projectRoot, '.geminiignore');
|
||||
return fs.existsSync(ignoreFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user