-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: make search_files respect .gitignore files by default #7924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Modified ripgrep service to respect .gitignore files by default - Added optional 'include_ignored' parameter to include ignored files when needed - Updated tool description to document the new behavior - Added tests to verify the gitignore handling Fixes #7921
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code feels like debugging in a mirror - everything looks backward but the bugs are still mine.
// The implementation has been updated to: | ||
// 1. By default, ripgrep respects .gitignore files (no --no-ignore flag) | ||
// 2. When includeIgnored is true, it adds --no-ignore flag to include ignored files | ||
// This behavior is implemented in src/services/ripgrep/index.ts lines 154-159 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I appreciate my own comment about integration tests requiring file system setup, wouldn't it be better to actually write those tests? We could use a temporary directory structure to verify the gitignore behavior works correctly with nested .gitignore files.
@@ -52,12 +54,16 @@ export async function searchFilesTool( | |||
|
|||
cline.consecutiveMistakeCount = 0 | |||
|
|||
// Parse includeIgnored as boolean (default to false) | |||
const shouldIncludeIgnored = includeIgnored === "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional that we only check for the exact string "true"? What happens if someone passes "yes", "1", or "TRUE"? Should we consider adding validation or at least normalizing the input to handle common boolean representations?
@@ -2,22 +2,31 @@ import { ToolArgs } from "./types" | |||
|
|||
export function getSearchFilesDescription(args: ToolArgs): string { | |||
return `## search_files | |||
Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context. | |||
Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context. By default, the tool respects .gitignore files (including nested ones) and excludes ignored paths from results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we be more explicit here about the nested .gitignore behavior? Something like: "By default, the tool respects ALL .gitignore files in the directory tree (including nested ones), not just the root .gitignore." This would make the behavior crystal clear to users.
const args = ["--json", "-e", regex, "--glob", filePattern || "*", "--context", "1", "--no-messages"] | ||
|
||
// By default, ripgrep respects .gitignore files. Add --no-ignore to include ignored files | ||
if (includeIgnored) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment here explaining the design decision would help future maintainers (including future me who will forget why I did this). Something like:
I think this tool should not return git ignored files, allowing the model to decide will probably not help. In any case, this should be controlled by a setting rather than the model itself. |
Summary
This PR fixes issue #7921 where the search_files tool was including results from directories/files that nested .gitignore files marked as ignored.
Problem
The search_files tool was returning results from ignored paths when running from the repository root in projects with .gitignore files inside subdirectories. This added noise to search results and increased output size unnecessarily.
Solution
Modified the ripgrep service to respect .gitignore files by default, while providing an optional parameter to include ignored files when explicitly requested.
Changes Made
Modified ripgrep service (
src/services/ripgrep/index.ts
):includeIgnored
parameter (default: false) toregexSearchFiles
function--no-ignore
flag to ripgrep whenincludeIgnored
is trueUpdated search_files tool (
src/core/tools/searchFilesTool.ts
):include_ignored
parameterUpdated tool description (
src/core/prompts/tools/search-files.ts
):include_ignored
parameter documentationUpdated type definitions:
include_ignored
to tool parameter names (src/shared/tools.ts
)SearchFilesToolUse
interfaceincludeIgnored
toClineSayTool
interface (src/shared/ExtensionMessage.ts
)Added tests (
src/services/ripgrep/__tests__/index.spec.ts
):Testing
Breaking Changes
None. The default behavior now respects .gitignore files, which is the expected behavior. Users can opt-in to include ignored files using the new parameter.
Example Usage
Default (respects .gitignore):
Include ignored files:
Fixes #7921
Important
The PR updates
search_files
to respect.gitignore
by default, with an option to include ignored files, and adds relevant tests and documentation.regexSearchFiles
inindex.ts
now respects.gitignore
by default, adding--no-ignore
only ifincludeIgnored
is true.searchFilesTool
insearchFilesTool.ts
parsesinclude_ignored
parameter and passes it toregexSearchFiles
.getSearchFilesDescription
insearch-files.ts
to document.gitignore
behavior andinclude_ignored
parameter.include_ignored
toSearchFilesToolUse
intools.ts
andClineSayTool
inExtensionMessage.ts
.index.spec.ts
to verify.gitignore
handling behavior.This description was created by
for d6fbdfb. You can customize this summary. It will automatically update as commits are pushed.