diff options
| author | Keith Ballinger <[email protected]> | 2025-06-03 21:40:46 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-04 04:40:46 +0000 |
| commit | c313762ba06ab1324dccd4c7663038cb56d24e53 (patch) | |
| tree | dbec46c12a06047ec1b79bfdfe6c8a5dd90a97be /packages/cli/src/ui/hooks/atCommandProcessor.ts | |
| parent | d85f09ac5129227932d3d6cf76b6dac36a325655 (diff) | |
Ignore folders files (#651)
# Add .gitignore-Aware File Filtering to gemini-cli
This pull request introduces .gitignore-based file filtering to the gemini-cli, ensuring that git-ignored files are automatically excluded from file-related operations and suggestions throughout the CLI. The update enhances usability, reduces noise from build artifacts and dependencies, and provides new configuration options for fine-tuning file discovery.
Key Improvements
.gitignore File Filtering
All @ (at) commands, file completions, and core discovery tools now honor .gitignore patterns by default.
Git-ignored files (such as node_modules/, dist/, .env, and .git) are excluded from results unless explicitly overridden.
The behavior can be customized via a new fileFiltering section in settings.json, including options for:
Turning .gitignore respect on/off.
Adding custom ignore patterns.
Allowing or excluding build artifacts.
Configuration & Documentation Updates
settings.json schema extended with fileFiltering options.
Documentation updated to explain new filtering controls and usage patterns.
Testing
New and updated integration/unit tests for file filtering logic, configuration merging, and edge cases.
Test coverage ensures .gitignore filtering works as intended across different workflows.
Internal Refactoring
Core file discovery logic refactored for maintainability and extensibility.
Underlying tools (ls, glob, read-many-files) now support git-aware filtering out of the box.
Co-authored-by: N. Taylor Mullen <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/hooks/atCommandProcessor.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/atCommandProcessor.ts | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/packages/cli/src/ui/hooks/atCommandProcessor.ts b/packages/cli/src/ui/hooks/atCommandProcessor.ts index ac56ab75..c534207c 100644 --- a/packages/cli/src/ui/hooks/atCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/atCommandProcessor.ts @@ -134,9 +134,14 @@ export async function handleAtCommand({ addItem({ type: 'user', text: query }, userMessageTimestamp); + // Get centralized file discovery service + const fileDiscovery = await config.getFileService(); + const respectGitIgnore = config.getFileFilteringRespectGitIgnore(); + const pathSpecsToRead: string[] = []; const atPathToResolvedSpecMap = new Map<string, string>(); const contentLabelsForDisplay: string[] = []; + const ignoredPaths: string[] = []; const toolRegistry = await config.getToolRegistry(); const readManyFilesTool = toolRegistry.getTool('read_many_files'); @@ -176,6 +181,16 @@ export async function handleAtCommand({ return { processedQuery: null, shouldProceed: false }; } + // Check if path should be ignored by git + if (fileDiscovery.shouldIgnoreFile(pathName)) { + const reason = respectGitIgnore + ? 'git-ignored and will be skipped' + : 'ignored by custom patterns'; + onDebugMessage(`Path ${pathName} is ${reason}.`); + ignoredPaths.push(pathName); + continue; + } + let currentPathSpec = pathName; let resolvedSuccessfully = false; @@ -305,6 +320,14 @@ export async function handleAtCommand({ } initialQueryText = initialQueryText.trim(); + // Inform user about ignored paths + if (ignoredPaths.length > 0) { + const ignoreType = respectGitIgnore ? 'git-ignored' : 'custom-ignored'; + onDebugMessage( + `Ignored ${ignoredPaths.length} ${ignoreType} files: ${ignoredPaths.join(', ')}`, + ); + } + // Fallback for lone "@" or completely invalid @-commands resulting in empty initialQueryText if (pathSpecsToRead.length === 0) { onDebugMessage('No valid file paths found in @ commands to read.'); @@ -324,7 +347,10 @@ export async function handleAtCommand({ const processedQueryParts: PartUnion[] = [{ text: initialQueryText }]; - const toolArgs = { paths: pathSpecsToRead }; + const toolArgs = { + paths: pathSpecsToRead, + respectGitIgnore, // Use configuration setting + }; let toolCallDisplay: IndividualToolCallDisplay; try { |
