diff --git a/src/core/ignore/__tests__/RooIgnoreController.test.ts b/src/core/ignore/__tests__/RooIgnoreController.test.ts index 1e5dbd5072..194ebf4fc0 100644 --- a/src/core/ignore/__tests__/RooIgnoreController.test.ts +++ b/src/core/ignore/__tests__/RooIgnoreController.test.ts @@ -215,6 +215,33 @@ describe("RooIgnoreController", () => { expect(emptyController.validateAccess("secrets/api-keys.json")).toBe(true) expect(emptyController.validateAccess(".git/HEAD")).toBe(true) }) + + /** + * Tests the specific scenario from GitHub issue #4647 + * where .next folders should be properly ignored when specified in .rooignore + */ + it("should correctly ignore .next folders in nested projects (GitHub issue #4647)", async () => { + // Setup .rooignore content that matches the GitHub issue scenario + mockFileExists.mockResolvedValue(true) + mockReadFile.mockResolvedValue("example-nextjs/.next/") + await controller.initialize() + + // Test files that should be ignored (in example-nextjs/.next/) + expect(controller.validateAccess("example-nextjs/.next/static/chunks/main.js")).toBe(false) + expect(controller.validateAccess("example-nextjs/.next/build-manifest.json")).toBe(false) + expect(controller.validateAccess("example-nextjs/.next/server/pages/index.js")).toBe(false) + + // Test files that should be allowed + expect(controller.validateAccess("example-nextjs/src/app.js")).toBe(true) + expect(controller.validateAccess("example-nextjs/package.json")).toBe(true) + expect(controller.validateAccess("other-project/.next/file.js")).toBe(true) + expect(controller.validateAccess(".next/standalone-file.js")).toBe(true) + + // Test that .git and .vscode are still handled by explicit ignore in listFiles + // (these should be allowed by RooIgnoreController since they're not in this .rooignore) + expect(controller.validateAccess(".git/config")).toBe(true) + expect(controller.validateAccess(".vscode/settings.json")).toBe(true) + }) }) describe("validateCommand", () => { diff --git a/src/services/glob/list-files.ts b/src/services/glob/list-files.ts index e1809ba4e8..4c38dafa4d 100644 --- a/src/services/glob/list-files.ts +++ b/src/services/glob/list-files.ts @@ -26,7 +26,12 @@ const DIRS_TO_IGNORE = [ "deps", "pkg", "Pods", - ".*", + ".git", + ".svn", + ".hg", + ".bzr", + ".vscode", + ".idea", ] /** @@ -156,14 +161,9 @@ function buildNonRecursiveArgs(): string[] { // Apply directory exclusions for non-recursive searches for (const dir of DIRS_TO_IGNORE) { - if (dir === ".*") { - // For hidden files/dirs in non-recursive mode - args.push("-g", "!.*") - } else { - // Direct children only - args.push("-g", `!${dir}`) - args.push("-g", `!${dir}/**`) - } + // Direct children only + args.push("-g", `!${dir}`) + args.push("-g", `!${dir}/**`) } return args @@ -237,11 +237,6 @@ async function listFilteredDirectories( * Determine if a directory should be included in results based on filters */ function shouldIncludeDirectory(dirName: string, recursive: boolean, gitignorePatterns: string[]): boolean { - // Skip hidden directories if configured to ignore them - if (dirName.startsWith(".") && DIRS_TO_IGNORE.includes(".*")) { - return false - } - // Check against explicit ignore patterns if (isDirectoryExplicitlyIgnored(dirName)) { return false