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

Uses 'SearchText' on all files even with respectGitIgnore=true

Open njam opened this issue 1 year ago • 11 comments

What happened?

I was asking gemini-cli to replace usages of Regex::new() with a macro. It would use the SearchText tool, but instead of only searching through the project files, it also searched through artifacts which are gitignored.

Is it expected that SearchText is searching also in gitignored files?

What did you expect to happen?

The SearchText should only search in non-ignored files, or gemini should use it more cleverly, e.g. only search in .rs files.

Client information

$ gemini /about
╭───────────────────────────────────────────────────────╮
│                                                       │
│ About Gemini CLI                                      │
│                                                       │
│ CLI Version       0.1.21                              │
│ Git Commit        055fe46d                            │
│ Model             gemini-2.5-pro                      │
│ Sandbox           no sandbox                          │
│ OS                linux                               │
│ Auth Method       gemini-api-key                      │
│                                                       │
╰───────────────────────────────────────────────────────╯

Login information

│ Auth Method gemini-api-key

Anything else we need to know?

No response

njam avatar Aug 15 '25 14:08 njam

We should respect the gitIgnore and geminiIgnore for SearchText. Likely we should do this by filtering the results from the underlying grep or ripgrep commands as it is likely not feasible to fully enforce them within those tools. If implemented as a post process this should be a fairly simple and robust fix.

jacob314 avatar Aug 20 '25 01:08 jacob314

Just to add that I had the feeling SearchText was very slow for me, probably also because it searched through a lot of big files (maybe even binary files), that are gitignored. From that perspective it would be better to only search through non-ignored files, instead of filter out results later.

njam avatar Aug 20 '25 07:08 njam

I would like to work on this. Could you please assign it to me?

qingshanyuluo avatar Sep 04 '25 12:09 qingshanyuluo

Will be looking into the issue. Thanks

gsehgal avatar Oct 11 '25 10:10 gsehgal

@njam ripGrep (rg) by default takes .gitignore into account and also excludes binary files. Does your system have ripGrep installed, if not it this a git repo. The reason I am asking these questions is to first understand which search strategy gemini is using in your case.

gsehgal avatar Oct 17 '25 05:10 gsehgal

@gsehgal hm, yes it was definitely a git repo, and I do have rg installed.

njam avatar Oct 17 '25 07:10 njam

@njam so would it be safe to say that cli end up using git grel (strategy 1) , because git grep would ignore binary files by default, the only thing won't include is .geminiexclude?

Also, could you please share which OS you were running gemini cli on?

gsehgal avatar Oct 18 '25 04:10 gsehgal

@njam have provided a fix where in Linux environment which don't have ripGrep installed the cli ends up using strategy 3 and does not use the 1st 2 strategy.

If you are running on Linux then you try the latest fix. Will update the ticket once the latest fix has been rolled out or if you want you can try the nightly version

gsehgal avatar Oct 20 '25 04:10 gsehgal

Hi @njam , please let me know if search performance has improved, as the fix has been rolled out.

gsehgal avatar Oct 30 '25 16:10 gsehgal

@gsehgal thanks a lot. Sorry, I'm currently not using Gemini-cli. Feel free to close it, thanks.

njam avatar Oct 31 '25 15:10 njam

@njam

Understood. Thanks for letting us know about your current usage of the Gemini CLI. I'll go ahead and close this out.

Should you decide to use it again in the future, please don't hesitate to reach out to us for any assistance—we'll be happy to help!

gsehgal avatar Oct 31 '25 15:10 gsehgal