refactor: Switch over to unified shouldIgnoreFile (#11815)

This commit is contained in:
Eric Rahm
2025-10-24 18:55:12 -07:00
committed by GitHub
parent 145e099ca5
commit b1059f891f
6 changed files with 51 additions and 84 deletions
@@ -12,6 +12,7 @@ import type {
ToolResult,
ToolCallConfirmationDetails,
GeminiCLIExtension,
FilterFilesOptions,
} from '@google/gemini-cli-core';
import {
AuthType,
@@ -571,7 +572,8 @@ class Session {
// Get centralized file discovery service
const fileDiscovery = this.config.getFileService();
const respectGitIgnore = this.config.getFileFilteringRespectGitIgnore();
const fileFilteringOptions: FilterFilesOptions =
this.config.getFileFilteringOptions();
const pathSpecsToRead: string[] = [];
const contentLabelsForDisplay: string[] = [];
@@ -587,13 +589,10 @@ class Session {
for (const atPathPart of atPathCommandParts) {
const pathName = atPathPart.fileData!.fileUri;
// Check if path should be ignored by git
if (fileDiscovery.shouldGitIgnoreFile(pathName)) {
// Check if path should be ignored
if (fileDiscovery.shouldIgnoreFile(pathName, fileFilteringOptions)) {
ignoredPaths.push(pathName);
const reason = respectGitIgnore
? 'git-ignored and will be skipped'
: 'ignored by custom patterns';
debugLogger.warn(`Path ${pathName} is ${reason}.`);
debugLogger.warn(`Path ${pathName} is ignored and will be skipped.`);
continue;
}
let currentPathSpec = pathName;
@@ -730,9 +729,8 @@ class Session {
initialQueryText = initialQueryText.trim();
// Inform user about ignored paths
if (ignoredPaths.length > 0) {
const ignoreType = respectGitIgnore ? 'git-ignored' : 'custom-ignored';
this.debug(
`Ignored ${ignoredPaths.length} ${ignoreType} files: ${ignoredPaths.join(', ')}`,
`Ignored ${ignoredPaths.length} files: ${ignoredPaths.join(', ')}`,
);
}
@@ -747,7 +745,6 @@ class Session {
if (pathSpecsToRead.length > 0) {
const toolArgs = {
paths: pathSpecsToRead,
respectGitIgnore, // Use configuration setting
};
const callId = `${readManyFilesTool.name}-${Date.now()}`;