mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 01:07:46 +00:00
Sync upstream Gemini-CLI v0.8.2 (#838)
This commit is contained in:
@@ -5,40 +5,34 @@
|
||||
*/
|
||||
|
||||
import type { GitIgnoreFilter } from '../utils/gitIgnoreParser.js';
|
||||
import type { QwenIgnoreFilter } from '../utils/qwenIgnoreParser.js';
|
||||
import { GitIgnoreParser } from '../utils/gitIgnoreParser.js';
|
||||
import { QwenIgnoreParser } from '../utils/qwenIgnoreParser.js';
|
||||
import { isGitRepository } from '../utils/gitUtils.js';
|
||||
import * as path from 'node:path';
|
||||
|
||||
const GEMINI_IGNORE_FILE_NAME = '.qwenignore';
|
||||
|
||||
export interface FilterFilesOptions {
|
||||
respectGitIgnore?: boolean;
|
||||
respectGeminiIgnore?: boolean;
|
||||
respectQwenIgnore?: boolean;
|
||||
}
|
||||
|
||||
export interface FilterReport {
|
||||
filteredPaths: string[];
|
||||
gitIgnoredCount: number;
|
||||
qwenIgnoredCount: number;
|
||||
}
|
||||
|
||||
export class FileDiscoveryService {
|
||||
private gitIgnoreFilter: GitIgnoreFilter | null = null;
|
||||
private geminiIgnoreFilter: GitIgnoreFilter | null = null;
|
||||
private qwenIgnoreFilter: QwenIgnoreFilter | null = null;
|
||||
private projectRoot: string;
|
||||
|
||||
constructor(projectRoot: string) {
|
||||
this.projectRoot = path.resolve(projectRoot);
|
||||
if (isGitRepository(this.projectRoot)) {
|
||||
const parser = new GitIgnoreParser(this.projectRoot);
|
||||
try {
|
||||
parser.loadGitRepoPatterns();
|
||||
} catch (_error) {
|
||||
// ignore file not found
|
||||
}
|
||||
this.gitIgnoreFilter = parser;
|
||||
this.gitIgnoreFilter = new GitIgnoreParser(this.projectRoot);
|
||||
}
|
||||
const gParser = new GitIgnoreParser(this.projectRoot);
|
||||
try {
|
||||
gParser.loadPatterns(GEMINI_IGNORE_FILE_NAME);
|
||||
} catch (_error) {
|
||||
// ignore file not found
|
||||
}
|
||||
this.geminiIgnoreFilter = gParser;
|
||||
this.qwenIgnoreFilter = new QwenIgnoreParser(this.projectRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,23 +42,56 @@ export class FileDiscoveryService {
|
||||
filePaths: string[],
|
||||
options: FilterFilesOptions = {
|
||||
respectGitIgnore: true,
|
||||
respectGeminiIgnore: true,
|
||||
respectQwenIgnore: true,
|
||||
},
|
||||
): string[] {
|
||||
return filePaths.filter((filePath) => {
|
||||
if (options.respectGitIgnore && this.shouldGitIgnoreFile(filePath)) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
options.respectGeminiIgnore &&
|
||||
this.shouldGeminiIgnoreFile(filePath)
|
||||
) {
|
||||
if (options.respectQwenIgnore && this.shouldQwenIgnoreFile(filePath)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters a list of file paths based on git ignore rules and returns a report
|
||||
* with counts of ignored files.
|
||||
*/
|
||||
filterFilesWithReport(
|
||||
filePaths: string[],
|
||||
opts: FilterFilesOptions = {
|
||||
respectGitIgnore: true,
|
||||
respectQwenIgnore: true,
|
||||
},
|
||||
): FilterReport {
|
||||
const filteredPaths: string[] = [];
|
||||
let gitIgnoredCount = 0;
|
||||
let qwenIgnoredCount = 0;
|
||||
|
||||
for (const filePath of filePaths) {
|
||||
if (opts.respectGitIgnore && this.shouldGitIgnoreFile(filePath)) {
|
||||
gitIgnoredCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (opts.respectQwenIgnore && this.shouldQwenIgnoreFile(filePath)) {
|
||||
qwenIgnoredCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
filteredPaths.push(filePath);
|
||||
}
|
||||
|
||||
return {
|
||||
filteredPaths,
|
||||
gitIgnoredCount,
|
||||
qwenIgnoredCount,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a single file should be git-ignored
|
||||
*/
|
||||
@@ -76,11 +103,11 @@ export class FileDiscoveryService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a single file should be gemini-ignored
|
||||
* Checks if a single file should be qwen-ignored
|
||||
*/
|
||||
shouldGeminiIgnoreFile(filePath: string): boolean {
|
||||
if (this.geminiIgnoreFilter) {
|
||||
return this.geminiIgnoreFilter.isIgnored(filePath);
|
||||
shouldQwenIgnoreFile(filePath: string): boolean {
|
||||
if (this.qwenIgnoreFilter) {
|
||||
return this.qwenIgnoreFilter.isIgnored(filePath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -92,12 +119,15 @@ export class FileDiscoveryService {
|
||||
filePath: string,
|
||||
options: FilterFilesOptions = {},
|
||||
): boolean {
|
||||
const { respectGitIgnore = true, respectGeminiIgnore = true } = options;
|
||||
const {
|
||||
respectGitIgnore = true,
|
||||
respectQwenIgnore: respectQwenIgnore = true,
|
||||
} = options;
|
||||
|
||||
if (respectGitIgnore && this.shouldGitIgnoreFile(filePath)) {
|
||||
return true;
|
||||
}
|
||||
if (respectGeminiIgnore && this.shouldGeminiIgnoreFile(filePath)) {
|
||||
if (respectQwenIgnore && this.shouldQwenIgnoreFile(filePath)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -106,7 +136,7 @@ export class FileDiscoveryService {
|
||||
/**
|
||||
* Returns loaded patterns from .qwenignore
|
||||
*/
|
||||
getGeminiIgnorePatterns(): string[] {
|
||||
return this.geminiIgnoreFilter?.getPatterns() ?? [];
|
||||
getQwenIgnorePatterns(): string[] {
|
||||
return this.qwenIgnoreFilter?.getPatterns() ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user