2025-05-20 13:02:41 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { describe, it, expect, vi, beforeEach, afterEach, Mock } from 'vitest';
|
|
|
|
|
import { handleAtCommand } from './atCommandProcessor.js';
|
2025-07-22 17:18:57 -07:00
|
|
|
import {
|
|
|
|
|
Config,
|
|
|
|
|
FileDiscoveryService,
|
|
|
|
|
GlobTool,
|
|
|
|
|
ReadManyFilesTool,
|
|
|
|
|
ToolRegistry,
|
|
|
|
|
} from '@google/gemini-cli-core';
|
|
|
|
|
import * as os from 'os';
|
2025-05-28 17:08:05 -07:00
|
|
|
import { ToolCallStatus } from '../types.js';
|
2025-05-20 13:02:41 -07:00
|
|
|
import { UseHistoryManagerReturn } from './useHistoryManager.js';
|
2025-05-28 17:08:05 -07:00
|
|
|
import * as fsPromises from 'fs/promises';
|
2025-07-22 17:18:57 -07:00
|
|
|
import * as path from '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
|
|
|
|
2025-05-20 13:02:41 -07:00
|
|
|
describe('handleAtCommand', () => {
|
2025-07-22 17:18:57 -07:00
|
|
|
let testRootDir: string;
|
|
|
|
|
let mockConfig: Config;
|
|
|
|
|
|
|
|
|
|
const mockAddItem: Mock<UseHistoryManagerReturn['addItem']> = vi.fn();
|
|
|
|
|
const mockOnDebugMessage: Mock<(message: string) => void> = vi.fn();
|
|
|
|
|
|
2025-05-20 13:02:41 -07:00
|
|
|
let abortController: AbortController;
|
|
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
async function createTestFile(fullPath: string, fileContents: string) {
|
|
|
|
|
await fsPromises.mkdir(path.dirname(fullPath), { recursive: true });
|
|
|
|
|
await fsPromises.writeFile(fullPath, fileContents);
|
|
|
|
|
return path.resolve(testRootDir, fullPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2025-05-20 13:02:41 -07:00
|
|
|
vi.resetAllMocks();
|
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-22 17:18:57 -07:00
|
|
|
testRootDir = await fsPromises.mkdtemp(
|
|
|
|
|
path.join(os.tmpdir(), 'folder-structure-test-'),
|
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-22 17:18:57 -07:00
|
|
|
abortController = new AbortController();
|
|
|
|
|
|
|
|
|
|
const getToolRegistry = vi.fn();
|
|
|
|
|
|
|
|
|
|
mockConfig = {
|
|
|
|
|
getToolRegistry,
|
|
|
|
|
getTargetDir: () => testRootDir,
|
|
|
|
|
isSandboxed: () => false,
|
|
|
|
|
getFileService: () => new FileDiscoveryService(testRootDir),
|
|
|
|
|
getFileFilteringRespectGitIgnore: () => true,
|
|
|
|
|
getFileFilteringRespectGeminiIgnore: () => true,
|
|
|
|
|
getFileFilteringOptions: () => ({
|
|
|
|
|
respectGitIgnore: true,
|
|
|
|
|
respectGeminiIgnore: true,
|
|
|
|
|
}),
|
|
|
|
|
getEnableRecursiveFileSearch: vi.fn(() => true),
|
|
|
|
|
} as unknown as Config;
|
|
|
|
|
|
|
|
|
|
const registry = new ToolRegistry(mockConfig);
|
|
|
|
|
registry.registerTool(new ReadManyFilesTool(mockConfig));
|
|
|
|
|
registry.registerTool(new GlobTool(mockConfig));
|
|
|
|
|
getToolRegistry.mockReturnValue(registry);
|
2025-05-20 13:02:41 -07:00
|
|
|
});
|
|
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
afterEach(async () => {
|
2025-05-28 17:08:05 -07:00
|
|
|
abortController.abort();
|
2025-07-22 17:18:57 -07:00
|
|
|
await fsPromises.rm(testRootDir, { recursive: true, force: true });
|
2025-05-20 13:02:41 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should pass through query if no @ command is present', async () => {
|
|
|
|
|
const query = 'regular user query';
|
2025-07-22 17:18:57 -07:00
|
|
|
|
2025-05-20 13:02:41 -07:00
|
|
|
const result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 123,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
2025-07-22 17:18:57 -07:00
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [{ text: query }],
|
|
|
|
|
shouldProceed: true,
|
|
|
|
|
});
|
2025-05-20 13:02:41 -07:00
|
|
|
expect(mockAddItem).toHaveBeenCalledWith(
|
|
|
|
|
{ type: 'user', text: query },
|
|
|
|
|
123,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-28 17:08:05 -07:00
|
|
|
it('should pass through original query if only a lone @ symbol is present', async () => {
|
2025-05-20 13:02:41 -07:00
|
|
|
const queryWithSpaces = ' @ ';
|
2025-07-22 17:18:57 -07:00
|
|
|
|
2025-05-20 13:02:41 -07:00
|
|
|
const result = await handleAtCommand({
|
2025-05-28 17:08:05 -07:00
|
|
|
query: queryWithSpaces,
|
2025-05-20 13:02:41 -07:00
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 124,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
2025-07-22 17:18:57 -07:00
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [{ text: queryWithSpaces }],
|
|
|
|
|
shouldProceed: true,
|
|
|
|
|
});
|
2025-05-20 13:02:41 -07:00
|
|
|
expect(mockAddItem).toHaveBeenCalledWith(
|
|
|
|
|
{ type: 'user', text: queryWithSpaces },
|
|
|
|
|
124,
|
|
|
|
|
);
|
|
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
2025-05-28 17:08:05 -07:00
|
|
|
'Lone @ detected, will be treated as text in the modified query.',
|
2025-05-20 13:02:41 -07:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should process a valid text file path', async () => {
|
|
|
|
|
const fileContent = 'This is the file content.';
|
2025-07-22 17:18:57 -07:00
|
|
|
const filePath = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'path', 'to', 'file.txt'),
|
|
|
|
|
fileContent,
|
|
|
|
|
);
|
|
|
|
|
const query = `@${filePath}`;
|
2025-05-20 13:02:41 -07:00
|
|
|
|
|
|
|
|
const result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 125,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
2025-07-22 17:18:57 -07:00
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [
|
|
|
|
|
{ text: `@${filePath}` },
|
|
|
|
|
{ text: '\n--- Content from referenced files ---' },
|
|
|
|
|
{ text: `\nContent from @${filePath}:\n` },
|
|
|
|
|
{ text: fileContent },
|
|
|
|
|
{ text: '\n--- End of content ---' },
|
|
|
|
|
],
|
|
|
|
|
shouldProceed: true,
|
|
|
|
|
});
|
2025-05-20 13:02:41 -07:00
|
|
|
expect(mockAddItem).toHaveBeenCalledWith(
|
|
|
|
|
{ type: 'user', text: query },
|
|
|
|
|
125,
|
|
|
|
|
);
|
|
|
|
|
expect(mockAddItem).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
type: 'tool_group',
|
2025-05-28 17:08:05 -07:00
|
|
|
tools: [expect.objectContaining({ status: ToolCallStatus.Success })],
|
2025-05-20 13:02:41 -07:00
|
|
|
}),
|
|
|
|
|
125,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should process a valid directory path and convert to glob', async () => {
|
2025-07-22 17:18:57 -07:00
|
|
|
const fileContent = 'This is the file content.';
|
|
|
|
|
const filePath = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'path', 'to', 'file.txt'),
|
|
|
|
|
fileContent,
|
|
|
|
|
);
|
|
|
|
|
const dirPath = path.dirname(filePath);
|
2025-05-20 13:02:41 -07:00
|
|
|
const query = `@${dirPath}`;
|
2025-05-28 17:08:05 -07:00
|
|
|
const resolvedGlob = `${dirPath}/**`;
|
2025-05-20 13:02:41 -07:00
|
|
|
|
|
|
|
|
const result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 126,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
2025-07-22 17:18:57 -07:00
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [
|
|
|
|
|
{ text: `@${resolvedGlob}` },
|
|
|
|
|
{ text: '\n--- Content from referenced files ---' },
|
|
|
|
|
{ text: `\nContent from @${filePath}:\n` },
|
|
|
|
|
{ text: fileContent },
|
|
|
|
|
{ text: '\n--- End of content ---' },
|
|
|
|
|
],
|
|
|
|
|
shouldProceed: true,
|
|
|
|
|
});
|
2025-05-20 13:02:41 -07:00
|
|
|
expect(mockAddItem).toHaveBeenCalledWith(
|
|
|
|
|
{ type: 'user', text: query },
|
|
|
|
|
126,
|
|
|
|
|
);
|
|
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
2025-05-28 17:08:05 -07:00
|
|
|
`Path ${dirPath} resolved to directory, using glob: ${resolvedGlob}`,
|
2025-05-20 13:02:41 -07:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should handle query with text before and after @command', async () => {
|
2025-07-22 17:18:57 -07:00
|
|
|
const fileContent = 'Markdown content.';
|
|
|
|
|
const filePath = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'doc.md'),
|
|
|
|
|
fileContent,
|
|
|
|
|
);
|
2025-05-28 17:08:05 -07:00
|
|
|
const textBefore = 'Explain this: ';
|
|
|
|
|
const textAfter = ' in detail.';
|
|
|
|
|
const query = `${textBefore}@${filePath}${textAfter}`;
|
2025-05-20 13:02:41 -07:00
|
|
|
|
|
|
|
|
const result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 128,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
2025-07-22 17:18:57 -07:00
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [
|
|
|
|
|
{ text: `${textBefore}@${filePath}${textAfter}` },
|
|
|
|
|
{ text: '\n--- Content from referenced files ---' },
|
|
|
|
|
{ text: `\nContent from @${filePath}:\n` },
|
|
|
|
|
{ text: fileContent },
|
|
|
|
|
{ text: '\n--- End of content ---' },
|
|
|
|
|
],
|
|
|
|
|
shouldProceed: true,
|
|
|
|
|
});
|
2025-05-20 13:02:41 -07:00
|
|
|
expect(mockAddItem).toHaveBeenCalledWith(
|
2025-05-28 17:08:05 -07:00
|
|
|
{ type: 'user', text: query },
|
2025-05-20 13:02:41 -07:00
|
|
|
128,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should correctly unescape paths with escaped spaces', async () => {
|
2025-07-22 17:18:57 -07:00
|
|
|
const fileContent = 'This is the file content.';
|
|
|
|
|
const filePath = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'path', 'to', 'my file.txt'),
|
|
|
|
|
fileContent,
|
|
|
|
|
);
|
|
|
|
|
const escapedpath = path.join(testRootDir, 'path', 'to', 'my\\ file.txt');
|
|
|
|
|
const query = `@${escapedpath}`;
|
2025-05-20 13:02:41 -07:00
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
const result = await handleAtCommand({
|
2025-05-20 13:02:41 -07:00
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
2025-07-22 17:18:57 -07:00
|
|
|
messageId: 125,
|
2025-05-20 13:02:41 -07:00
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
2025-07-22 17:18:57 -07:00
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [
|
|
|
|
|
{ text: `@${filePath}` },
|
|
|
|
|
{ text: '\n--- Content from referenced files ---' },
|
|
|
|
|
{ text: `\nContent from @${filePath}:\n` },
|
|
|
|
|
{ text: fileContent },
|
|
|
|
|
{ text: '\n--- End of content ---' },
|
|
|
|
|
],
|
|
|
|
|
shouldProceed: true,
|
|
|
|
|
});
|
|
|
|
|
expect(mockAddItem).toHaveBeenCalledWith(
|
|
|
|
|
{ type: 'user', text: query },
|
|
|
|
|
125,
|
|
|
|
|
);
|
|
|
|
|
expect(mockAddItem).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
type: 'tool_group',
|
|
|
|
|
tools: [expect.objectContaining({ status: ToolCallStatus.Success })],
|
|
|
|
|
}),
|
|
|
|
|
125,
|
2025-05-28 17:08:05 -07:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should handle multiple @file references', async () => {
|
|
|
|
|
const content1 = 'Content file1';
|
2025-07-22 17:18:57 -07:00
|
|
|
const file1Path = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'file1.txt'),
|
|
|
|
|
content1,
|
|
|
|
|
);
|
2025-05-28 17:08:05 -07:00
|
|
|
const content2 = 'Content file2';
|
2025-07-22 17:18:57 -07:00
|
|
|
const file2Path = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'file2.md'),
|
|
|
|
|
content2,
|
|
|
|
|
);
|
|
|
|
|
const query = `@${file1Path} @${file2Path}`;
|
2025-05-28 17:08:05 -07:00
|
|
|
|
|
|
|
|
const result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 130,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
2025-07-22 17:18:57 -07:00
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [
|
|
|
|
|
{ text: query },
|
|
|
|
|
{ text: '\n--- Content from referenced files ---' },
|
|
|
|
|
{ text: `\nContent from @${file1Path}:\n` },
|
|
|
|
|
{ text: content1 },
|
|
|
|
|
{ text: `\nContent from @${file2Path}:\n` },
|
|
|
|
|
{ text: content2 },
|
|
|
|
|
{ text: '\n--- End of content ---' },
|
|
|
|
|
],
|
|
|
|
|
shouldProceed: true,
|
|
|
|
|
});
|
2025-05-28 17:08:05 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should handle multiple @file references with interleaved text', async () => {
|
|
|
|
|
const text1 = 'Check ';
|
|
|
|
|
const content1 = 'C1';
|
2025-07-22 17:18:57 -07:00
|
|
|
const file1Path = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'f1.txt'),
|
|
|
|
|
content1,
|
|
|
|
|
);
|
2025-05-28 17:08:05 -07:00
|
|
|
const text2 = ' and ';
|
|
|
|
|
const content2 = 'C2';
|
2025-07-22 17:18:57 -07:00
|
|
|
const file2Path = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'f2.md'),
|
|
|
|
|
content2,
|
|
|
|
|
);
|
2025-05-28 17:08:05 -07:00
|
|
|
const text3 = ' please.';
|
2025-07-22 17:18:57 -07:00
|
|
|
const query = `${text1}@${file1Path}${text2}@${file2Path}${text3}`;
|
2025-05-28 17:08:05 -07:00
|
|
|
|
|
|
|
|
const result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 131,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
2025-07-22 17:18:57 -07:00
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [
|
|
|
|
|
{ text: query },
|
|
|
|
|
{ text: '\n--- Content from referenced files ---' },
|
|
|
|
|
{ text: `\nContent from @${file1Path}:\n` },
|
|
|
|
|
{ text: content1 },
|
|
|
|
|
{ text: `\nContent from @${file2Path}:\n` },
|
|
|
|
|
{ text: content2 },
|
|
|
|
|
{ text: '\n--- End of content ---' },
|
|
|
|
|
],
|
|
|
|
|
shouldProceed: true,
|
|
|
|
|
});
|
2025-05-28 17:08:05 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should handle a mix of valid, invalid, and lone @ references', async () => {
|
|
|
|
|
const content1 = 'Valid content 1';
|
2025-07-22 17:18:57 -07:00
|
|
|
const file1Path = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'valid1.txt'),
|
|
|
|
|
content1,
|
|
|
|
|
);
|
2025-05-28 17:08:05 -07:00
|
|
|
const invalidFile = 'nonexistent.txt';
|
|
|
|
|
const content2 = 'Globbed content';
|
2025-07-22 17:18:57 -07:00
|
|
|
const file2Path = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'resolved', 'valid2.actual'),
|
|
|
|
|
content2,
|
|
|
|
|
);
|
|
|
|
|
const query = `Look at @${file1Path} then @${invalidFile} and also just @ symbol, then @${file2Path}`;
|
2025-05-28 17:08:05 -07:00
|
|
|
|
|
|
|
|
const result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 132,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [
|
|
|
|
|
{
|
|
|
|
|
text: `Look at @${file1Path} then @${invalidFile} and also just @ symbol, then @${file2Path}`,
|
2025-07-20 00:55:33 -07:00
|
|
|
},
|
2025-07-22 17:18:57 -07:00
|
|
|
{ text: '\n--- Content from referenced files ---' },
|
|
|
|
|
{ text: `\nContent from @${file2Path}:\n` },
|
|
|
|
|
{ text: content2 },
|
|
|
|
|
{ text: `\nContent from @${file1Path}:\n` },
|
|
|
|
|
{ text: content1 },
|
|
|
|
|
{ text: '\n--- End of content ---' },
|
|
|
|
|
],
|
|
|
|
|
shouldProceed: true,
|
|
|
|
|
});
|
2025-05-28 17:08:05 -07:00
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
|
|
|
|
`Path ${invalidFile} not found directly, attempting glob search.`,
|
|
|
|
|
);
|
|
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
|
|
|
|
`Glob search for '**/*${invalidFile}*' found no files or an error. Path ${invalidFile} will be skipped.`,
|
|
|
|
|
);
|
|
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
|
|
|
|
'Lone @ detected, will be treated as text in the modified query.',
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return original query if all @paths are invalid or lone @', async () => {
|
|
|
|
|
const query = 'Check @nonexistent.txt and @ also';
|
|
|
|
|
|
|
|
|
|
const result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 133,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
2025-05-31 16:19:14 -07:00
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [{ text: 'Check @nonexistent.txt and @ also' }],
|
|
|
|
|
shouldProceed: true,
|
2025-05-31 16:19:14 -07:00
|
|
|
});
|
2025-05-20 13:02:41 -07: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>
2025-06-03 21:40:46 -07:00
|
|
|
|
|
|
|
|
describe('git-aware filtering', () => {
|
2025-07-22 17:18:57 -07:00
|
|
|
beforeEach(async () => {
|
|
|
|
|
await fsPromises.mkdir(path.join(testRootDir, '.git'), {
|
|
|
|
|
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-22 17:18:57 -07:00
|
|
|
it('should skip git-ignored files in @ commands', async () => {
|
|
|
|
|
await createTestFile(
|
|
|
|
|
path.join(testRootDir, '.gitignore'),
|
|
|
|
|
'node_modules/package.json',
|
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-22 17:18:57 -07:00
|
|
|
const gitIgnoredFile = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'node_modules', 'package.json'),
|
|
|
|
|
'the file contents',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const query = `@${gitIgnoredFile}`;
|
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 result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 200,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [{ text: query }],
|
|
|
|
|
shouldProceed: 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
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
|
|
|
|
`Path ${gitIgnoredFile} is git-ignored and will be skipped.`,
|
|
|
|
|
);
|
|
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
2025-07-22 17:18:57 -07:00
|
|
|
`Ignored 1 files:\nGit-ignored: ${gitIgnoredFile}`,
|
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 process non-git-ignored files normally', async () => {
|
2025-07-22 17:18:57 -07:00
|
|
|
await createTestFile(
|
|
|
|
|
path.join(testRootDir, '.gitignore'),
|
|
|
|
|
'node_modules/package.json',
|
2025-07-20 00:55:33 -07:00
|
|
|
);
|
2025-07-22 17:18:57 -07:00
|
|
|
|
|
|
|
|
const validFile = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'src', 'index.ts'),
|
|
|
|
|
'console.log("Hello world");',
|
|
|
|
|
);
|
|
|
|
|
const query = `@${validFile}`;
|
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 result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 201,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [
|
|
|
|
|
{ text: `@${validFile}` },
|
|
|
|
|
{ text: '\n--- Content from referenced files ---' },
|
|
|
|
|
{ text: `\nContent from @${validFile}:\n` },
|
|
|
|
|
{ text: 'console.log("Hello world");' },
|
|
|
|
|
{ text: '\n--- End of content ---' },
|
|
|
|
|
],
|
|
|
|
|
shouldProceed: 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
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should handle mixed git-ignored and valid files', async () => {
|
2025-07-22 17:18:57 -07:00
|
|
|
await createTestFile(path.join(testRootDir, '.gitignore'), '.env');
|
|
|
|
|
const validFile = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'README.md'),
|
|
|
|
|
'# Project README',
|
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-22 17:18:57 -07:00
|
|
|
const gitIgnoredFile = await createTestFile(
|
|
|
|
|
path.join(testRootDir, '.env'),
|
|
|
|
|
'SECRET=123',
|
|
|
|
|
);
|
|
|
|
|
const query = `@${validFile} @${gitIgnoredFile}`;
|
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 result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 202,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [
|
|
|
|
|
{ text: `@${validFile} @${gitIgnoredFile}` },
|
|
|
|
|
{ text: '\n--- Content from referenced files ---' },
|
|
|
|
|
{ text: `\nContent from @${validFile}:\n` },
|
|
|
|
|
{ text: '# Project README' },
|
|
|
|
|
{ text: '\n--- End of content ---' },
|
|
|
|
|
],
|
|
|
|
|
shouldProceed: 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
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
|
|
|
|
`Path ${gitIgnoredFile} is git-ignored and will be skipped.`,
|
|
|
|
|
);
|
|
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
2025-07-22 17:18:57 -07:00
|
|
|
`Ignored 1 files:\nGit-ignored: ${gitIgnoredFile}`,
|
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 always ignore .git directory files', async () => {
|
2025-07-22 17:18:57 -07:00
|
|
|
const gitFile = await createTestFile(
|
|
|
|
|
path.join(testRootDir, '.git', 'config'),
|
|
|
|
|
'[core]\n\trepositoryformatversion = 0\n',
|
2025-07-20 00:55:33 -07:00
|
|
|
);
|
2025-07-22 17:18:57 -07:00
|
|
|
const query = `@${gitFile}`;
|
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 result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 203,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [{ text: query }],
|
|
|
|
|
shouldProceed: 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
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
|
|
|
|
`Path ${gitFile} is git-ignored and will be skipped.`,
|
|
|
|
|
);
|
2025-07-20 00:55:33 -07:00
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
2025-07-22 17:18:57 -07:00
|
|
|
`Ignored 1 files:\nGit-ignored: ${gitFile}`,
|
2025-07-20 00:55:33 -07: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>
2025-06-03 21:40:46 -07:00
|
|
|
});
|
|
|
|
|
});
|
2025-06-23 23:48:26 -07:00
|
|
|
|
|
|
|
|
describe('when recursive file search is disabled', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.mocked(mockConfig.getEnableRecursiveFileSearch).mockReturnValue(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not use glob search for a nonexistent file', async () => {
|
|
|
|
|
const invalidFile = 'nonexistent.txt';
|
|
|
|
|
const query = `@${invalidFile}`;
|
|
|
|
|
|
|
|
|
|
const result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 300,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
|
|
|
|
`Glob tool not found. Path ${invalidFile} will be skipped.`,
|
|
|
|
|
);
|
|
|
|
|
expect(result.processedQuery).toEqual([{ text: query }]);
|
|
|
|
|
expect(result.shouldProceed).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-07-20 00:55:33 -07:00
|
|
|
|
|
|
|
|
describe('gemini-ignore filtering', () => {
|
|
|
|
|
it('should skip gemini-ignored files in @ commands', async () => {
|
2025-07-22 17:18:57 -07:00
|
|
|
await createTestFile(
|
|
|
|
|
path.join(testRootDir, '.geminiignore'),
|
|
|
|
|
'build/output.js',
|
|
|
|
|
);
|
|
|
|
|
const geminiIgnoredFile = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'build', 'output.js'),
|
|
|
|
|
'console.log("Hello");',
|
2025-07-20 00:55:33 -07:00
|
|
|
);
|
2025-07-22 17:18:57 -07:00
|
|
|
const query = `@${geminiIgnoredFile}`;
|
2025-07-20 00:55:33 -07:00
|
|
|
|
|
|
|
|
const result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 204,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [{ text: query }],
|
|
|
|
|
shouldProceed: true,
|
|
|
|
|
});
|
2025-07-20 00:55:33 -07:00
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
|
|
|
|
`Path ${geminiIgnoredFile} is gemini-ignored and will be skipped.`,
|
|
|
|
|
);
|
|
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
2025-07-22 17:18:57 -07:00
|
|
|
`Ignored 1 files:\nGemini-ignored: ${geminiIgnoredFile}`,
|
2025-07-20 00:55:33 -07:00
|
|
|
);
|
|
|
|
|
});
|
2025-07-22 17:18:57 -07:00
|
|
|
});
|
|
|
|
|
it('should process non-ignored files when .geminiignore is present', async () => {
|
|
|
|
|
await createTestFile(
|
|
|
|
|
path.join(testRootDir, '.geminiignore'),
|
|
|
|
|
'build/output.js',
|
|
|
|
|
);
|
|
|
|
|
const validFile = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'src', 'index.ts'),
|
|
|
|
|
'console.log("Hello world");',
|
|
|
|
|
);
|
|
|
|
|
const query = `@${validFile}`;
|
2025-07-20 00:55:33 -07:00
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
const result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 205,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
2025-07-20 00:55:33 -07:00
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [
|
2025-07-20 00:55:33 -07:00
|
|
|
{ text: `@${validFile}` },
|
|
|
|
|
{ text: '\n--- Content from referenced files ---' },
|
|
|
|
|
{ text: `\nContent from @${validFile}:\n` },
|
2025-07-22 17:18:57 -07:00
|
|
|
{ text: 'console.log("Hello world");' },
|
2025-07-20 00:55:33 -07:00
|
|
|
{ text: '\n--- End of content ---' },
|
2025-07-22 17:18:57 -07:00
|
|
|
],
|
|
|
|
|
shouldProceed: true,
|
2025-07-20 00:55:33 -07:00
|
|
|
});
|
2025-07-22 17:18:57 -07:00
|
|
|
});
|
2025-07-20 00:55:33 -07:00
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
it('should handle mixed gemini-ignored and valid files', async () => {
|
|
|
|
|
await createTestFile(
|
|
|
|
|
path.join(testRootDir, '.geminiignore'),
|
|
|
|
|
'dist/bundle.js',
|
|
|
|
|
);
|
|
|
|
|
const validFile = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'src', 'main.ts'),
|
|
|
|
|
'// Main application entry',
|
|
|
|
|
);
|
|
|
|
|
const geminiIgnoredFile = await createTestFile(
|
|
|
|
|
path.join(testRootDir, 'dist', 'bundle.js'),
|
|
|
|
|
'console.log("bundle");',
|
|
|
|
|
);
|
|
|
|
|
const query = `@${validFile} @${geminiIgnoredFile}`;
|
2025-07-20 00:55:33 -07:00
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
const result = await handleAtCommand({
|
|
|
|
|
query,
|
|
|
|
|
config: mockConfig,
|
|
|
|
|
addItem: mockAddItem,
|
|
|
|
|
onDebugMessage: mockOnDebugMessage,
|
|
|
|
|
messageId: 206,
|
|
|
|
|
signal: abortController.signal,
|
|
|
|
|
});
|
2025-07-20 00:55:33 -07:00
|
|
|
|
2025-07-22 17:18:57 -07:00
|
|
|
expect(result).toEqual({
|
|
|
|
|
processedQuery: [
|
2025-07-20 00:55:33 -07:00
|
|
|
{ text: `@${validFile} @${geminiIgnoredFile}` },
|
|
|
|
|
{ text: '\n--- Content from referenced files ---' },
|
|
|
|
|
{ text: `\nContent from @${validFile}:\n` },
|
2025-07-22 17:18:57 -07:00
|
|
|
{ text: '// Main application entry' },
|
2025-07-20 00:55:33 -07:00
|
|
|
{ text: '\n--- End of content ---' },
|
2025-07-22 17:18:57 -07:00
|
|
|
],
|
|
|
|
|
shouldProceed: true,
|
2025-07-20 00:55:33 -07:00
|
|
|
});
|
2025-07-22 17:18:57 -07:00
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
|
|
|
|
`Path ${geminiIgnoredFile} is gemini-ignored and will be skipped.`,
|
|
|
|
|
);
|
|
|
|
|
expect(mockOnDebugMessage).toHaveBeenCalledWith(
|
|
|
|
|
`Ignored 1 files:\nGemini-ignored: ${geminiIgnoredFile}`,
|
|
|
|
|
);
|
2025-07-20 00:55:33 -07:00
|
|
|
});
|
2025-07-22 17:18:57 -07:00
|
|
|
// });
|
2025-05-20 13:02:41 -07:00
|
|
|
});
|