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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2026-01-27 17:19:13 -08:00
|
|
|
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
2025-08-25 22:11:27 +02:00
|
|
|
import * as fs from 'node:fs/promises';
|
|
|
|
|
import * as os from 'node:os';
|
|
|
|
|
import * as path from 'node:path';
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
import { FileDiscoveryService } from './fileDiscoveryService.js';
|
2026-01-27 17:19:13 -08:00
|
|
|
import { GEMINI_IGNORE_FILE_NAME } from '../config/constants.js';
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
|
|
|
|
|
describe('FileDiscoveryService', () => {
|
2025-07-25 14:30:15 -07:00
|
|
|
let testRootDir: string;
|
|
|
|
|
let projectRoot: string;
|
|
|
|
|
|
|
|
|
|
async function createTestFile(filePath: string, content = '') {
|
|
|
|
|
const fullPath = path.join(projectRoot, filePath);
|
|
|
|
|
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
|
|
|
|
await fs.writeFile(fullPath, content);
|
|
|
|
|
return fullPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
testRootDir = await fs.mkdtemp(
|
|
|
|
|
path.join(os.tmpdir(), 'file-discovery-test-'),
|
|
|
|
|
);
|
|
|
|
|
projectRoot = path.join(testRootDir, 'project');
|
|
|
|
|
await fs.mkdir(projectRoot, { recursive: true });
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
|
2025-07-25 14:30:15 -07:00
|
|
|
afterEach(async () => {
|
|
|
|
|
await fs.rm(testRootDir, { recursive: true, force: true });
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('initialization', () => {
|
2025-07-25 14:30:15 -07:00
|
|
|
it('should initialize git ignore parser by default in a git repo', async () => {
|
|
|
|
|
await fs.mkdir(path.join(projectRoot, '.git'));
|
|
|
|
|
await createTestFile('.gitignore', 'node_modules/');
|
|
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
// Let's check the effect of the parser instead of mocking it.
|
2025-10-24 18:55:12 -07:00
|
|
|
expect(service.shouldIgnoreFile('node_modules/foo.js')).toBe(true);
|
|
|
|
|
expect(service.shouldIgnoreFile('src/foo.js')).toBe(false);
|
2025-07-25 14:30:15 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not load git repo patterns when not in a git repo', async () => {
|
|
|
|
|
// No .git directory
|
|
|
|
|
await createTestFile('.gitignore', 'node_modules/');
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
|
|
|
|
|
// .gitignore is not loaded in non-git repos
|
2025-10-24 18:55:12 -07:00
|
|
|
expect(service.shouldIgnoreFile('node_modules/foo.js')).toBe(false);
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
|
2025-07-25 14:30:15 -07:00
|
|
|
it('should load .geminiignore patterns even when not in a git repo', async () => {
|
2026-01-27 17:19:13 -08:00
|
|
|
await createTestFile(GEMINI_IGNORE_FILE_NAME, 'secrets.txt');
|
2025-07-25 14:30:15 -07:00
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
|
2025-10-24 18:55:12 -07:00
|
|
|
expect(service.shouldIgnoreFile('secrets.txt')).toBe(true);
|
|
|
|
|
expect(service.shouldIgnoreFile('src/index.js')).toBe(false);
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
2026-01-27 17:19:13 -08:00
|
|
|
|
|
|
|
|
it('should call applyFilterFilesOptions in constructor', () => {
|
|
|
|
|
const resolveSpy = vi.spyOn(
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
FileDiscoveryService.prototype as any,
|
|
|
|
|
'applyFilterFilesOptions',
|
|
|
|
|
);
|
|
|
|
|
const options = { respectGitIgnore: false };
|
|
|
|
|
new FileDiscoveryService(projectRoot, options);
|
|
|
|
|
expect(resolveSpy).toHaveBeenCalledWith(options);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should correctly resolve options passed to constructor', () => {
|
|
|
|
|
const options = {
|
|
|
|
|
respectGitIgnore: false,
|
|
|
|
|
respectGeminiIgnore: false,
|
|
|
|
|
customIgnoreFilePaths: ['custom/.ignore'],
|
|
|
|
|
};
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot, options);
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
const defaults = (service as any).defaultFilterFileOptions;
|
|
|
|
|
|
|
|
|
|
expect(defaults.respectGitIgnore).toBe(false);
|
|
|
|
|
expect(defaults.respectGeminiIgnore).toBe(false);
|
|
|
|
|
expect(defaults.customIgnoreFilePaths).toStrictEqual(['custom/.ignore']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should use defaults when options are not provided', () => {
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
const defaults = (service as any).defaultFilterFileOptions;
|
|
|
|
|
|
|
|
|
|
expect(defaults.respectGitIgnore).toBe(true);
|
|
|
|
|
expect(defaults.respectGeminiIgnore).toBe(true);
|
|
|
|
|
expect(defaults.customIgnoreFilePaths).toStrictEqual([]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should partially override defaults', () => {
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot, {
|
|
|
|
|
respectGitIgnore: false,
|
|
|
|
|
});
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
const defaults = (service as any).defaultFilterFileOptions;
|
|
|
|
|
|
|
|
|
|
expect(defaults.respectGitIgnore).toBe(false);
|
|
|
|
|
expect(defaults.respectGeminiIgnore).toBe(true);
|
|
|
|
|
});
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('filterFiles', () => {
|
2025-07-25 14:30:15 -07:00
|
|
|
beforeEach(async () => {
|
|
|
|
|
await fs.mkdir(path.join(projectRoot, '.git'));
|
|
|
|
|
await createTestFile('.gitignore', 'node_modules/\n.git/\ndist');
|
2026-01-27 17:19:13 -08:00
|
|
|
await createTestFile(GEMINI_IGNORE_FILE_NAME, 'logs/');
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
|
2025-07-25 14:30:15 -07:00
|
|
|
it('should filter out git-ignored and gemini-ignored files by default', () => {
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
const files = [
|
|
|
|
|
'src/index.ts',
|
|
|
|
|
'node_modules/package/index.js',
|
|
|
|
|
'README.md',
|
|
|
|
|
'.git/config',
|
|
|
|
|
'dist/bundle.js',
|
2025-07-25 14:30:15 -07:00
|
|
|
'logs/latest.log',
|
|
|
|
|
].map((f) => path.join(projectRoot, f));
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
|
2025-07-25 14:30:15 -07:00
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
|
2025-07-25 14:30:15 -07:00
|
|
|
expect(service.filterFiles(files)).toEqual(
|
|
|
|
|
['src/index.ts', 'README.md'].map((f) => path.join(projectRoot, f)),
|
|
|
|
|
);
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not filter files when respectGitIgnore is false', () => {
|
|
|
|
|
const files = [
|
|
|
|
|
'src/index.ts',
|
|
|
|
|
'node_modules/package/index.js',
|
|
|
|
|
'.git/config',
|
2025-07-25 14:30:15 -07:00
|
|
|
'logs/latest.log',
|
|
|
|
|
].map((f) => path.join(projectRoot, f));
|
|
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
|
|
|
|
|
const filtered = service.filterFiles(files, {
|
|
|
|
|
respectGitIgnore: false,
|
|
|
|
|
respectGeminiIgnore: true, // still respect this one
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(filtered).toEqual(
|
|
|
|
|
['src/index.ts', 'node_modules/package/index.js', '.git/config'].map(
|
|
|
|
|
(f) => path.join(projectRoot, f),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not filter files when respectGeminiIgnore is false', () => {
|
|
|
|
|
const files = [
|
|
|
|
|
'src/index.ts',
|
|
|
|
|
'node_modules/package/index.js',
|
|
|
|
|
'logs/latest.log',
|
|
|
|
|
].map((f) => path.join(projectRoot, f));
|
|
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
|
2025-07-25 14:30:15 -07:00
|
|
|
const filtered = service.filterFiles(files, {
|
|
|
|
|
respectGitIgnore: true,
|
|
|
|
|
respectGeminiIgnore: false,
|
|
|
|
|
});
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
|
2025-07-25 14:30:15 -07:00
|
|
|
expect(filtered).toEqual(
|
|
|
|
|
['src/index.ts', 'logs/latest.log'].map((f) =>
|
|
|
|
|
path.join(projectRoot, f),
|
|
|
|
|
),
|
|
|
|
|
);
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should handle empty file list', () => {
|
2025-07-25 14:30:15 -07:00
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
|
|
|
|
|
expect(service.filterFiles([])).toEqual([]);
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-22 17:06:31 -07:00
|
|
|
describe('filterFilesWithReport', () => {
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
await fs.mkdir(path.join(projectRoot, '.git'));
|
|
|
|
|
await createTestFile('.gitignore', 'node_modules/');
|
2026-01-27 17:19:13 -08:00
|
|
|
await createTestFile(GEMINI_IGNORE_FILE_NAME, '*.log');
|
2025-10-22 17:06:31 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return filtered paths and correct ignored count', () => {
|
|
|
|
|
const files = [
|
|
|
|
|
'src/index.ts',
|
|
|
|
|
'node_modules/package/index.js',
|
|
|
|
|
'debug.log',
|
|
|
|
|
'README.md',
|
|
|
|
|
].map((f) => path.join(projectRoot, f));
|
|
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
const report = service.filterFilesWithReport(files);
|
|
|
|
|
|
|
|
|
|
expect(report.filteredPaths).toEqual(
|
|
|
|
|
['src/index.ts', 'README.md'].map((f) => path.join(projectRoot, f)),
|
|
|
|
|
);
|
|
|
|
|
expect(report.ignoredCount).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should handle no ignored files', () => {
|
|
|
|
|
const files = ['src/index.ts', 'README.md'].map((f) =>
|
|
|
|
|
path.join(projectRoot, f),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
const report = service.filterFilesWithReport(files);
|
|
|
|
|
|
|
|
|
|
expect(report.filteredPaths).toEqual(files);
|
|
|
|
|
expect(report.ignoredCount).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-25 14:30:15 -07:00
|
|
|
describe('shouldGitIgnoreFile & shouldGeminiIgnoreFile', () => {
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
await fs.mkdir(path.join(projectRoot, '.git'));
|
|
|
|
|
await createTestFile('.gitignore', 'node_modules/');
|
2026-01-27 17:19:13 -08:00
|
|
|
await createTestFile(GEMINI_IGNORE_FILE_NAME, '*.log');
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return true for git-ignored files', () => {
|
2025-07-25 14:30:15 -07:00
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
|
|
|
|
|
expect(
|
2025-10-24 18:55:12 -07:00
|
|
|
service.shouldIgnoreFile(
|
2025-07-25 14:30:15 -07:00
|
|
|
path.join(projectRoot, 'node_modules/package/index.js'),
|
|
|
|
|
),
|
|
|
|
|
).toBe(true);
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
|
2025-07-25 14:30:15 -07:00
|
|
|
it('should return false for non-git-ignored files', () => {
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
|
|
|
|
|
expect(
|
2025-10-24 18:55:12 -07:00
|
|
|
service.shouldIgnoreFile(path.join(projectRoot, 'src/index.ts')),
|
2025-07-25 14:30:15 -07:00
|
|
|
).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return true for gemini-ignored files', () => {
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
|
|
|
|
|
expect(
|
2025-10-24 18:55:12 -07:00
|
|
|
service.shouldIgnoreFile(path.join(projectRoot, 'debug.log')),
|
2025-07-25 14:30:15 -07:00
|
|
|
).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return false for non-gemini-ignored files', () => {
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
|
|
|
|
|
expect(
|
2025-10-24 18:55:12 -07:00
|
|
|
service.shouldIgnoreFile(path.join(projectRoot, 'src/index.ts')),
|
2025-07-25 14:30:15 -07:00
|
|
|
).toBe(false);
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('edge cases', () => {
|
2025-07-25 14:30:15 -07:00
|
|
|
it('should handle relative project root paths', async () => {
|
|
|
|
|
await fs.mkdir(path.join(projectRoot, '.git'));
|
|
|
|
|
await createTestFile('.gitignore', 'ignored.txt');
|
|
|
|
|
const service = new FileDiscoveryService(
|
|
|
|
|
path.relative(process.cwd(), projectRoot),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(
|
2025-10-24 18:55:12 -07:00
|
|
|
service.shouldIgnoreFile(path.join(projectRoot, 'ignored.txt')),
|
2025-07-25 14:30:15 -07:00
|
|
|
).toBe(true);
|
|
|
|
|
expect(
|
2025-10-24 18:55:12 -07:00
|
|
|
service.shouldIgnoreFile(path.join(projectRoot, 'not-ignored.txt')),
|
2025-07-25 14:30:15 -07:00
|
|
|
).toBe(false);
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
|
2025-07-25 14:30:15 -07:00
|
|
|
it('should handle filterFiles with undefined options', async () => {
|
|
|
|
|
await fs.mkdir(path.join(projectRoot, '.git'));
|
|
|
|
|
await createTestFile('.gitignore', 'ignored.txt');
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
|
|
|
|
|
const files = ['src/index.ts', 'ignored.txt'].map((f) =>
|
|
|
|
|
path.join(projectRoot, f),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(service.filterFiles(files, undefined)).toEqual([
|
|
|
|
|
path.join(projectRoot, 'src/index.ts'),
|
|
|
|
|
]);
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
});
|
2025-11-01 10:06:34 -07:00
|
|
|
describe('precedence (.geminiignore over .gitignore)', () => {
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
await fs.mkdir(path.join(projectRoot, '.git'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should un-ignore a file in .geminiignore that is ignored in .gitignore', async () => {
|
|
|
|
|
await createTestFile('.gitignore', '*.txt');
|
2026-01-27 17:19:13 -08:00
|
|
|
await createTestFile(GEMINI_IGNORE_FILE_NAME, '!important.txt');
|
2025-11-01 10:06:34 -07:00
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
const files = ['file.txt', 'important.txt'].map((f) =>
|
|
|
|
|
path.join(projectRoot, f),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const filtered = service.filterFiles(files);
|
|
|
|
|
expect(filtered).toEqual([path.join(projectRoot, 'important.txt')]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should un-ignore a directory in .geminiignore that is ignored in .gitignore', async () => {
|
|
|
|
|
await createTestFile('.gitignore', 'logs/');
|
2026-01-27 17:19:13 -08:00
|
|
|
await createTestFile(GEMINI_IGNORE_FILE_NAME, '!logs/');
|
2025-11-01 10:06:34 -07:00
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
const files = ['logs/app.log', 'other/app.log'].map((f) =>
|
|
|
|
|
path.join(projectRoot, f),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const filtered = service.filterFiles(files);
|
|
|
|
|
expect(filtered).toEqual(files);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should extend ignore rules in .geminiignore', async () => {
|
|
|
|
|
await createTestFile('.gitignore', '*.log');
|
2026-01-27 17:19:13 -08:00
|
|
|
await createTestFile(GEMINI_IGNORE_FILE_NAME, 'temp/');
|
2025-11-01 10:06:34 -07:00
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
const files = ['app.log', 'temp/file.txt'].map((f) =>
|
|
|
|
|
path.join(projectRoot, f),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const filtered = service.filterFiles(files);
|
|
|
|
|
expect(filtered).toEqual([]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should use .gitignore rules if respectGeminiIgnore is false', async () => {
|
|
|
|
|
await createTestFile('.gitignore', '*.txt');
|
2026-01-27 17:19:13 -08:00
|
|
|
await createTestFile(GEMINI_IGNORE_FILE_NAME, '!important.txt');
|
2025-11-01 10:06:34 -07:00
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
const files = ['file.txt', 'important.txt'].map((f) =>
|
|
|
|
|
path.join(projectRoot, f),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const filtered = service.filterFiles(files, {
|
|
|
|
|
respectGitIgnore: true,
|
|
|
|
|
respectGeminiIgnore: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(filtered).toEqual([]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should use .geminiignore rules if respectGitIgnore is false', async () => {
|
|
|
|
|
await createTestFile('.gitignore', '*.txt');
|
2026-01-27 17:19:13 -08:00
|
|
|
await createTestFile(GEMINI_IGNORE_FILE_NAME, '!important.txt\ntemp/');
|
2025-11-01 10:06:34 -07:00
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
const files = ['file.txt', 'important.txt', 'temp/file.js'].map((f) =>
|
|
|
|
|
path.join(projectRoot, f),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const filtered = service.filterFiles(files, {
|
|
|
|
|
respectGitIgnore: false,
|
|
|
|
|
respectGeminiIgnore: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// .gitignore is ignored, so *.txt is not applied.
|
|
|
|
|
// .geminiignore un-ignores important.txt (which wasn't ignored anyway)
|
|
|
|
|
// and ignores temp/
|
|
|
|
|
expect(filtered).toEqual(
|
|
|
|
|
['file.txt', 'important.txt'].map((f) => path.join(projectRoot, f)),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-01-27 17:19:13 -08:00
|
|
|
|
|
|
|
|
describe('custom ignore file', () => {
|
|
|
|
|
it('should respect patterns from a custom ignore file', async () => {
|
|
|
|
|
const customIgnoreName = '.customignore';
|
|
|
|
|
await createTestFile(customIgnoreName, '*.secret');
|
|
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot, {
|
|
|
|
|
customIgnoreFilePaths: [customIgnoreName],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const files = ['file.txt', 'file.secret'].map((f) =>
|
|
|
|
|
path.join(projectRoot, f),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const filtered = service.filterFiles(files);
|
|
|
|
|
expect(filtered).toEqual([path.join(projectRoot, 'file.txt')]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should prioritize custom ignore patterns over .geminiignore patterns in git repo', async () => {
|
|
|
|
|
await fs.mkdir(path.join(projectRoot, '.git'));
|
|
|
|
|
await createTestFile('.gitignore', 'node_modules/');
|
|
|
|
|
await createTestFile(GEMINI_IGNORE_FILE_NAME, '*.log');
|
|
|
|
|
|
|
|
|
|
const customIgnoreName = '.customignore';
|
|
|
|
|
// .geminiignore ignores *.log, custom un-ignores debug.log
|
|
|
|
|
await createTestFile(customIgnoreName, '!debug.log');
|
|
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot, {
|
|
|
|
|
customIgnoreFilePaths: [customIgnoreName],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const files = ['debug.log', 'error.log'].map((f) =>
|
|
|
|
|
path.join(projectRoot, f),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const filtered = service.filterFiles(files);
|
|
|
|
|
expect(filtered).toEqual([path.join(projectRoot, 'debug.log')]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should prioritize custom ignore patterns over .geminiignore patterns in non-git repo', async () => {
|
|
|
|
|
// No .git directory created
|
|
|
|
|
await createTestFile(GEMINI_IGNORE_FILE_NAME, 'secret.txt');
|
|
|
|
|
|
|
|
|
|
const customIgnoreName = '.customignore';
|
|
|
|
|
// .geminiignore ignores secret.txt, custom un-ignores it
|
|
|
|
|
await createTestFile(customIgnoreName, '!secret.txt');
|
|
|
|
|
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot, {
|
|
|
|
|
customIgnoreFilePaths: [customIgnoreName],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const files = ['secret.txt'].map((f) => path.join(projectRoot, f));
|
|
|
|
|
|
|
|
|
|
const filtered = service.filterFiles(files);
|
|
|
|
|
expect(filtered).toEqual([path.join(projectRoot, 'secret.txt')]);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getIgnoreFilePaths & getAllIgnoreFilePaths', () => {
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
await fs.mkdir(path.join(projectRoot, '.git'));
|
|
|
|
|
await createTestFile('.gitignore', '*.log');
|
|
|
|
|
await createTestFile(GEMINI_IGNORE_FILE_NAME, '*.tmp');
|
|
|
|
|
await createTestFile('.customignore', '*.secret');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return .geminiignore path by default', () => {
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
const paths = service.getIgnoreFilePaths();
|
|
|
|
|
expect(paths).toEqual([path.join(projectRoot, GEMINI_IGNORE_FILE_NAME)]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not return .geminiignore path if respectGeminiIgnore is false', () => {
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot, {
|
|
|
|
|
respectGeminiIgnore: false,
|
|
|
|
|
});
|
|
|
|
|
const paths = service.getIgnoreFilePaths();
|
|
|
|
|
expect(paths).toEqual([]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return custom ignore file paths', () => {
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot, {
|
|
|
|
|
customIgnoreFilePaths: ['.customignore'],
|
|
|
|
|
});
|
|
|
|
|
const paths = service.getIgnoreFilePaths();
|
|
|
|
|
expect(paths).toContain(path.join(projectRoot, GEMINI_IGNORE_FILE_NAME));
|
|
|
|
|
expect(paths).toContain(path.join(projectRoot, '.customignore'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return all ignore paths including .gitignore', () => {
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
const paths = service.getAllIgnoreFilePaths();
|
|
|
|
|
expect(paths).toContain(path.join(projectRoot, GEMINI_IGNORE_FILE_NAME));
|
|
|
|
|
expect(paths).toContain(path.join(projectRoot, '.gitignore'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not return .gitignore if respectGitIgnore is false', () => {
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot, {
|
|
|
|
|
respectGitIgnore: false,
|
|
|
|
|
});
|
|
|
|
|
const paths = service.getAllIgnoreFilePaths();
|
|
|
|
|
expect(paths).toContain(path.join(projectRoot, GEMINI_IGNORE_FILE_NAME));
|
|
|
|
|
expect(paths).not.toContain(path.join(projectRoot, '.gitignore'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not return .gitignore if it does not exist', async () => {
|
|
|
|
|
await fs.rm(path.join(projectRoot, '.gitignore'));
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
const paths = service.getAllIgnoreFilePaths();
|
|
|
|
|
expect(paths).not.toContain(path.join(projectRoot, '.gitignore'));
|
|
|
|
|
expect(paths).toContain(path.join(projectRoot, GEMINI_IGNORE_FILE_NAME));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should ensure .gitignore is the first file in the list', () => {
|
|
|
|
|
const service = new FileDiscoveryService(projectRoot);
|
|
|
|
|
const paths = service.getAllIgnoreFilePaths();
|
|
|
|
|
expect(paths[0]).toBe(path.join(projectRoot, '.gitignore'));
|
|
|
|
|
});
|
|
|
|
|
});
|
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 <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
|
|
|
});
|