feat: add respectGitIgnore setting to control .gitignore filtering#11250
feat: add respectGitIgnore setting to control .gitignore filtering#11250roomote[bot] wants to merge 2 commits intomainfrom
Conversation
…ross all file listing Adds a new `codebaseIndexRespectGitIgnore` setting (default: true) that controls whether .gitignore patterns are respected when listing files. This affects: - Code indexer scanner (original issue scope) - list_files tool (AI task file listings) - Environment details (workspace file context) - WorkspaceTracker (workspace file tracking) When disabled (false), only .rooignore is used for filtering, allowing gitignored files (e.g. external API headers) to be discovered and indexed. Changes: - packages/types: Add codebaseIndexRespectGitIgnore to schema and types - src/services/glob/list-files.ts: Add respectGitIgnore parameter - Pass --no-ignore-vcs to ripgrep when false - Skip gitignore patterns in createIgnoreInstance when false - src/services/code-index: Thread setting through manager, factory, scanner - src/core: Thread setting through ListFilesTool, getEnvironmentDetails - src/integrations/workspace: Thread setting through WorkspaceTracker - webview-ui: Add toggle in CodeIndexPopover advanced settings - i18n: Add English translations for new setting Closes #11249
Re-reviewed after 7973a57. Both previously flagged issues are resolved. No new issues found.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| let respectGitIgnore = true | ||
| try { | ||
| const content = await fs.readFile(ignorePath, "utf8") | ||
| ignoreInstance.add(content) | ||
| ignoreInstance.add(".gitignore") | ||
| } catch (error) { | ||
| // Should never happen: reading file failed even though it exists | ||
| console.error("Unexpected error loading .gitignore:", error) | ||
| TelemetryService.instance.captureEvent(TelemetryEventName.CODE_INDEX_ERROR, { | ||
| error: error instanceof Error ? error.message : String(error), | ||
| stack: error instanceof Error ? error.stack : undefined, | ||
| location: "_recreateServices", | ||
| }) | ||
| const codebaseIndexConfig = this._configManager!.getContextProxy()?.getGlobalState("codebaseIndexConfig") | ||
| respectGitIgnore = codebaseIndexConfig?.codebaseIndexRespectGitIgnore ?? true | ||
| } catch { | ||
| // Fall back to default (respect .gitignore) if config proxy is not available | ||
| } |
There was a problem hiding this comment.
Toggling codebaseIndexRespectGitIgnore won't actually cause the code index to re-scan with the new value. doesConfigChangeRequireRestart in config-manager.ts does not compare previous vs. current respectGitIgnore, so handleSettingsChange() will see requiresRestart: false and skip service recreation. The scanner retains the stale value until something else (e.g., a provider change) forces a restart. The fix is to track respectGitIgnore in PreviousConfigSnapshot, populate it in loadConfiguration, and compare it in doesConfigChangeRequireRestart.
Fix it with Roo Code or mention @roomote and request a fix.
src/services/glob/list-files.ts
Outdated
| * Build ripgrep arguments for recursive directory traversal | ||
| */ | ||
| function buildRecursiveArgs(dirPath: string): string[] { | ||
| function buildRecursiveArgs(dirPath: string, respectGitIgnore: boolean = true): string[] { |
There was a problem hiding this comment.
Nit: respectGitIgnore is accepted as a parameter here but never referenced in the function body (same for buildNonRecursiveArgs). The actual --no-ignore-vcs flag is correctly added in buildRipgrepArgs, so these parameters are dead code. Consider removing them to avoid confusing future readers into thinking these functions contain gitignore-related branching logic.
Fix it with Roo Code or mention @roomote and request a fix.
|
@roomote Should the setting visible to users be simply "Respect .gitignore"? (In the config schema, simply respectGitIgnore.) |
Renamed |
This PR attempts to address Issue #11249, specifically the follow-up comment by @emeraldcheshire asking whether the setting should apply beyond just the indexer.
Summary
Adds a new
codebaseIndexRespectGitIgnoresetting (default:true) that controls whether.gitignorepatterns are respected when listing files. The setting affects all file-listing functionality in Roo Code, not just the indexer:list_filestool - when the AI requests a directory listing during tasksWhen disabled (
false), only.rooignoreis used for filtering, allowing gitignored files (e.g., external API headers) to be discovered and indexed.Changes
packages/types: AddcodebaseIndexRespectGitIgnoreto the codebase index config schema and typessrc/services/glob/list-files.ts: Add optionalrespectGitIgnoreparameter--no-ignore-vcsto ripgrep whenfalse.gitignorepatterns increateIgnoreInstancewhenfalsesrc/services/code-index: Thread setting through manager, factory, and scannersrc/core: Thread setting throughListFilesToolandgetEnvironmentDetailssrc/integrations/workspace: Thread setting throughWorkspaceTrackerwebview-ui: Add toggle in CodeIndexPopover advanced settingsTesting
All existing tests pass (45 tests across 5 test files). Updated the WorkspaceTracker test to account for the new parameter.
Feedback and guidance are welcome.
Important
Introduces
respectGitIgnoresetting to control.gitignorefiltering across file-listing functionalities, with UI integration and configuration updates.respectGitIgnoresetting to control.gitignorefiltering across all file-listing functionalities.true, meaning.gitignoreis respected; whenfalse, only.rooignoreis used.codebaseIndexConfigSchemaincodebase-index.tsto includerespectGitIgnore.respectGitIgnorethroughconfig-manager.ts,manager.ts, andservice-factory.ts.listFiles()inlist-files.tsto acceptrespectGitIgnoreparameter.DirectoryScannerinscanner.tsto userespectGitIgnore.WorkspaceTrackerinWorkspaceTracker.tsto considerrespectGitIgnore.respectGitIgnoreinCodeIndexPopover.tsx.settings.jsonfor the new setting.This description was created by
for 7973a57. You can customize this summary. It will automatically update as commits are pushed.