mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
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>
This commit is contained in:
@@ -11,16 +11,30 @@ import path from 'path';
|
||||
import fs from 'fs/promises';
|
||||
import os from 'os';
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'; // Removed vi
|
||||
import { FileDiscoveryService } from '../services/fileDiscoveryService.js';
|
||||
import { Config } from '../config/config.js';
|
||||
|
||||
describe('GlobTool', () => {
|
||||
let tempRootDir: string; // This will be the rootDirectory for the GlobTool instance
|
||||
let globTool: GlobTool;
|
||||
const abortSignal = new AbortController().signal;
|
||||
|
||||
// Mock config for testing
|
||||
const mockConfig = {
|
||||
getFileService: async () => {
|
||||
const service = new FileDiscoveryService(tempRootDir);
|
||||
await service.initialize({ respectGitIgnore: true });
|
||||
return service;
|
||||
},
|
||||
getFileFilteringRespectGitIgnore: () => true,
|
||||
getFileFilteringCustomIgnorePatterns: () => [],
|
||||
getFileFilteringAllowBuildArtifacts: () => false,
|
||||
} as Partial<Config> as Config;
|
||||
|
||||
beforeEach(async () => {
|
||||
// Create a unique root directory for each test run
|
||||
tempRootDir = await fs.mkdtemp(path.join(os.tmpdir(), 'glob-tool-root-'));
|
||||
globTool = new GlobTool(tempRootDir);
|
||||
globTool = new GlobTool(tempRootDir, mockConfig);
|
||||
|
||||
// Create some test files and directories within this root
|
||||
// Top-level files
|
||||
@@ -214,7 +228,7 @@ describe('GlobTool', () => {
|
||||
it("should return error if search path resolves outside the tool's root directory", () => {
|
||||
// Create a globTool instance specifically for this test, with a deeper root
|
||||
const deeperRootDir = path.join(tempRootDir, 'sub');
|
||||
const specificGlobTool = new GlobTool(deeperRootDir);
|
||||
const specificGlobTool = new GlobTool(deeperRootDir, mockConfig);
|
||||
// const params: GlobToolParams = { pattern: '*.txt', path: '..' }; // This line is unused and will be removed.
|
||||
// This should be fine as tempRootDir is still within the original tempRootDir (the parent of deeperRootDir)
|
||||
// Let's try to go further up.
|
||||
|
||||
Reference in New Issue
Block a user