mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-14 13:53:02 -07:00
Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
This commit is contained in:
committed by
GitHub
parent
c0d5ab1f1e
commit
8e58df72c6
@@ -502,6 +502,50 @@ describe('FileDiscoveryService', () => {
|
|||||||
const paths = service.getAllIgnoreFilePaths();
|
const paths = service.getAllIgnoreFilePaths();
|
||||||
expect(paths[0]).toBe(path.join(projectRoot, '.gitignore'));
|
expect(paths[0]).toBe(path.join(projectRoot, '.gitignore'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should exclude directories from getIgnoreFilePaths (#19868)', async () => {
|
||||||
|
// Create a directory that shares a name with a customIgnoreFilePaths entry
|
||||||
|
await fs.mkdir(path.join(projectRoot, 'node_modules'), {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const service = new FileDiscoveryService(projectRoot, {
|
||||||
|
customIgnoreFilePaths: ['node_modules'],
|
||||||
|
});
|
||||||
|
const paths = service.getIgnoreFilePaths();
|
||||||
|
|
||||||
|
// node_modules/ is a directory, not a file — it should be excluded
|
||||||
|
expect(paths).not.toContain(path.join(projectRoot, 'node_modules'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should exclude directories from getAllIgnoreFilePaths (#19868)', async () => {
|
||||||
|
await fs.mkdir(path.join(projectRoot, 'node_modules'), {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const service = new FileDiscoveryService(projectRoot, {
|
||||||
|
customIgnoreFilePaths: ['node_modules'],
|
||||||
|
});
|
||||||
|
const paths = service.getAllIgnoreFilePaths();
|
||||||
|
|
||||||
|
expect(paths).not.toContain(path.join(projectRoot, 'node_modules'));
|
||||||
|
// .gitignore should still be present
|
||||||
|
expect(paths).toContain(path.join(projectRoot, '.gitignore'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not crash when customIgnoreFilePaths contains directory names (#19868)', async () => {
|
||||||
|
await fs.mkdir(path.join(projectRoot, 'node_modules'), {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
await fs.mkdir(path.join(projectRoot, 'temp'), { recursive: true });
|
||||||
|
|
||||||
|
// This is the exact user scenario from issue #19868
|
||||||
|
expect(() => {
|
||||||
|
new FileDiscoveryService(projectRoot, {
|
||||||
|
customIgnoreFilePaths: ['node_modules/', 'temp/', 'cache/'],
|
||||||
|
});
|
||||||
|
}).not.toThrow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getIgnoredPaths', () => {
|
describe('getIgnoredPaths', () => {
|
||||||
|
|||||||
@@ -274,7 +274,8 @@ export class FileDiscoveryService {
|
|||||||
this.defaultFilterFileOptions.respectGitIgnore
|
this.defaultFilterFileOptions.respectGitIgnore
|
||||||
) {
|
) {
|
||||||
const gitIgnorePath = path.join(this.projectRoot, '.gitignore');
|
const gitIgnorePath = path.join(this.projectRoot, '.gitignore');
|
||||||
if (fs.existsSync(gitIgnorePath)) {
|
const stat = fs.statSync(gitIgnorePath, { throwIfNoEntry: false });
|
||||||
|
if (stat?.isFile()) {
|
||||||
paths.push(gitIgnorePath);
|
paths.push(gitIgnorePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,10 @@ export function loadIgnoreRules(
|
|||||||
const ignoreFiles = service.getAllIgnoreFilePaths();
|
const ignoreFiles = service.getAllIgnoreFilePaths();
|
||||||
|
|
||||||
for (const filePath of ignoreFiles) {
|
for (const filePath of ignoreFiles) {
|
||||||
if (fs.existsSync(filePath)) {
|
try {
|
||||||
ignorer.add(fs.readFileSync(filePath, 'utf8'));
|
ignorer.add(fs.readFileSync(filePath, 'utf8'));
|
||||||
|
} catch {
|
||||||
|
// Skip files that can't be read (e.g. directories, permission errors)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,10 @@ export class IgnoreFileParser implements IgnoreFileFilter {
|
|||||||
.slice()
|
.slice()
|
||||||
.reverse()
|
.reverse()
|
||||||
.map((fileName) => path.join(this.projectRoot, fileName))
|
.map((fileName) => path.join(this.projectRoot, fileName))
|
||||||
.filter((filePath) => fs.existsSync(filePath));
|
.filter(
|
||||||
|
(filePath) =>
|
||||||
|
fs.statSync(filePath, { throwIfNoEntry: false })?.isFile() ?? false,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user