gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

fix(core): Add `.geminiignore` support to SearchText tool

Open xyrolle opened this issue 1 month ago • 7 comments

The SearchText (ripgrep) tool was not respecting .geminiignore patterns, causing subagents to search through files that users explicitly wanted to exclude. This fix adds .geminiignore support by leveraging ripgrep's native --ignore-file flag, ensuring consistent ignore behavior across all tools

Details

  • Extended GeminiIgnoreParser with getIgnoreFilePath() to return the .geminiignore path when it exists and has valid patterns, and hasPatterns() to check if any patterns are defined
  • Added an existence check in getIgnoreFilePath() to handle the race condition where the file could be deleted after the parser is instantiated
  • Updated RipGrepTool to cache the GeminiIgnoreParser instance, avoiding redundant file I/O on repeated tool calls
  • Ripgrep natively handles .gitignore, so no changes needed there
  • Added 8 unit tests for the new 1GeminiIgnoreParser` methods

Related Issues

Partially Fixes: https://github.com/google-gemini/gemini-cli/issues/13651

How to Validate

  1. Create a file (example file.md) with 1 word "carrot" in it
  2. add this file to .geminiignore
  3. gemini "please find "carrot" in the project"
  4. observe that result is not found

behaviour before fix:

  • I found one instance of 'carrot' in file.md. file.md*: Line 1 (carrot)

Pre-Merge Checklist

  • [ ] Updated relevant documentation and README (if needed)
  • [x] Added/updated tests (if needed)
  • [x] Noted breaking changes (if any)
  • [ ] Validated on required platforms/methods:
    • [x] MacOS
      • [x] npm run
      • [x] npx
      • [ ] Docker
      • [ ] Podman
      • [ ] Seatbelt
    • [ ] Windows
      • [ ] npm run
      • [ ] npx
      • [ ] Docker
    • [ ] Linux
      • [ ] npm run
      • [ ] npx
      • [ ] Docker

xyrolle avatar Nov 24 '25 20:11 xyrolle