From de408fec5d239ef7da0f8b47b3c51618dbda2e77 Mon Sep 17 00:00:00 2001 From: Alex Southwell <4596216+saphid@users.noreply.github.com> Date: Tue, 3 Nov 2026 09:04:53 +1100 Subject: [PATCH 1/3] fix(server): files tree labels ignored folders inside git submodules Co-Authored-By: Claude Opus 5.5 --- .../src/workspace/WorkspaceEntries.test.ts | 15 +++++++++++ apps/server/src/workspace/WorkspaceEntries.ts | 25 ++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/apps/server/src/workspace/WorkspaceEntries.test.ts b/apps/server/src/workspace/WorkspaceEntries.test.ts index d861935fe17cc..f0503bdbc5d82 100644 --- a/apps/server/src/workspace/WorkspaceEntries.test.ts +++ b/apps/server/src/workspace/WorkspaceEntries.test.ts @@ -108,6 +108,10 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => { yield* writeTextFile(cwd, "node_modules/pkg/index.js"); yield* writeTextFile(cwd, "src/index.ts"); yield* fileSystem.makeDirectory(path.join(cwd, "empty")); + yield* git(cwd, ["init", "sub"]); + yield* writeTextFile(cwd, "sub/.gitignore", "dist/\n"); + yield* writeTextFile(cwd, "sub/dist/out.js"); + yield* git(cwd, ["update-index", "--add", "--cacheinfo", `160000,${"1".repeat(40)},sub`]); const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; const root = yield* workspaceEntries.list({ cwd, directoryPath: "" }); @@ -127,6 +131,17 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => { entries: [{ path: "node_modules/pkg/index.js", kind: "file", ignored: true }], truncated: false, }); + // Git refuses pathspecs inside a submodule from the outer repository. + expect((yield* workspaceEntries.list({ cwd, directoryPath: "sub" })).entries).toEqual( + expect.arrayContaining([ + { path: "sub/.gitignore", kind: "file" }, + { path: "sub/dist", kind: "directory", ignored: true }, + ]), + ); + expect(yield* workspaceEntries.list({ cwd, directoryPath: "sub/dist" })).toEqual({ + entries: [{ path: "sub/dist/out.js", kind: "file", ignored: true }], + truncated: false, + }); expect(yield* workspaceEntries.list({ cwd, directoryPath: "empty" })).toEqual({ entries: [], truncated: false, diff --git a/apps/server/src/workspace/WorkspaceEntries.ts b/apps/server/src/workspace/WorkspaceEntries.ts index 0b853ccdaa437..b3484c8dfdcec 100644 --- a/apps/server/src/workspace/WorkspaceEntries.ts +++ b/apps/server/src/workspace/WorkspaceEntries.ts @@ -306,7 +306,7 @@ export const make = Effect.gen(function* () { relativePath: directoryPath, }) .pipe(Effect.mapError(toError)); - const { entries, throughSymlink } = yield* Effect.tryPromise({ + const { entries, throughSymlink, gitRoot } = yield* Effect.tryPromise({ try: async () => { const root = await NodeFSP.realpath(normalizedCwd); const directory = await NodeFSP.realpath(target.absolutePath); @@ -378,7 +378,18 @@ export const make = Effect.gen(function* () { )), ); } + // Git refuses paths inside a submodule from the outer repository, so ask the nearest one. + let gitRoot = ""; + const segments = target.relativePath.split("/").filter(Boolean); + for (let index = segments.length; index > 0 && !gitRoot; index -= 1) { + const candidate = segments.slice(0, index).join("/"); + const dotGit = await NodeFSP.lstat(path.join(normalizedCwd, candidate, ".git")).catch( + () => null, + ); + if (dotGit) gitRoot = candidate; + } return { + gitRoot, entries: children.flatMap((child, index): ProjectEntry[] => { const kind = kinds[index]; if (kind === undefined) return []; @@ -395,6 +406,8 @@ export const make = Effect.gen(function* () { }, catch: toError, }); + const gitPrefix = gitRoot ? `${gitRoot}/` : ""; + const directoryGitPath = target.relativePath.slice(gitPrefix.length); // stdin avoids argument limits; ignore classification is optional without git/repositories. const checkIgnore = (paths: ReadonlyArray) => vcsProcess @@ -402,8 +415,8 @@ export const make = Effect.gen(function* () { operation: "WorkspaceEntries.list", command: "git", args: ["-c", "core.fsmonitor=false", "check-ignore", "-z", "--stdin"], - cwd: normalizedCwd, - stdin: `${paths.join("\0")}\0`, + cwd: path.join(normalizedCwd, gitRoot), + stdin: `${paths.map((entryPath) => entryPath.slice(gitPrefix.length)).join("\0")}\0`, allowNonZeroExit: true, timeoutMs: 10_000, maxOutputBytes: 16 * 1024 * 1024, @@ -413,9 +426,9 @@ export const make = Effect.gen(function* () { // Symlinks and pathspec magic still need per-child checks. if ( entries.length > IGNORE_CHECK_CHUNK_SIZE && - target.relativePath !== "" && + directoryGitPath !== "" && !throughSymlink && - !/^:|[*?[\\]/.test(target.relativePath) && + !/^:|[*?[\\]/.test(directoryGitPath) && (yield* checkIgnore([target.relativePath]))?.exitCode === 0 ) { return { @@ -429,7 +442,7 @@ export const make = Effect.gen(function* () { entries.slice(offset, offset + IGNORE_CHECK_CHUNK_SIZE).map((entry) => entry.path), ); if (!result || (result.exitCode !== 0 && result.exitCode !== 1)) break; - for (const ignoredPath of result.stdout.split("\0")) ignored.add(ignoredPath); + for (const ignoredPath of result.stdout.split("\0")) ignored.add(gitPrefix + ignoredPath); } return { entries: entries.map((entry) => From c167ca32afd33432cf56e492fe0965625b878d64 Mon Sep 17 00:00:00 2001 From: Alex Southwell <4596216+saphid@users.noreply.github.com> Date: Tue, 3 Nov 2026 10:16:27 +1100 Subject: [PATCH 2/3] fix(server): nested clones keep the outer repo's ignored labels Only switch to the nested repository when git refuses its .git path, which it does for submodules but not for plain nested clones. The test fixture now derives the gitlink id from the repository so it also works with SHA-256 repositories. Co-Authored-By: Claude Opus 5.5 --- .../src/workspace/WorkspaceEntries.test.ts | 5 ++++- apps/server/src/workspace/WorkspaceEntries.ts | 21 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/server/src/workspace/WorkspaceEntries.test.ts b/apps/server/src/workspace/WorkspaceEntries.test.ts index f0503bdbc5d82..a835437515e11 100644 --- a/apps/server/src/workspace/WorkspaceEntries.test.ts +++ b/apps/server/src/workspace/WorkspaceEntries.test.ts @@ -111,7 +111,10 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => { yield* git(cwd, ["init", "sub"]); yield* writeTextFile(cwd, "sub/.gitignore", "dist/\n"); yield* writeTextFile(cwd, "sub/dist/out.js"); - yield* git(cwd, ["update-index", "--add", "--cacheinfo", `160000,${"1".repeat(40)},sub`]); + const gitlink = yield* git(cwd, ["hash-object", "tracked.txt"]); + yield* git(cwd, ["update-index", "--add", "--cacheinfo", `160000,${gitlink},sub`]); + // A nested clone that isn't a submodule keeps the outer repository's ignore rules. + yield* git(cwd, ["init", "node_modules/pkg"]); const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; const root = yield* workspaceEntries.list({ cwd, directoryPath: "" }); diff --git a/apps/server/src/workspace/WorkspaceEntries.ts b/apps/server/src/workspace/WorkspaceEntries.ts index b3484c8dfdcec..9d0f455deb9e4 100644 --- a/apps/server/src/workspace/WorkspaceEntries.ts +++ b/apps/server/src/workspace/WorkspaceEntries.ts @@ -306,7 +306,7 @@ export const make = Effect.gen(function* () { relativePath: directoryPath, }) .pipe(Effect.mapError(toError)); - const { entries, throughSymlink, gitRoot } = yield* Effect.tryPromise({ + const { entries, throughSymlink, nestedGitRoot } = yield* Effect.tryPromise({ try: async () => { const root = await NodeFSP.realpath(normalizedCwd); const directory = await NodeFSP.realpath(target.absolutePath); @@ -378,18 +378,17 @@ export const make = Effect.gen(function* () { )), ); } - // Git refuses paths inside a submodule from the outer repository, so ask the nearest one. - let gitRoot = ""; + let nestedGitRoot = ""; const segments = target.relativePath.split("/").filter(Boolean); - for (let index = segments.length; index > 0 && !gitRoot; index -= 1) { + for (let index = segments.length; index > 0 && !nestedGitRoot; index -= 1) { const candidate = segments.slice(0, index).join("/"); const dotGit = await NodeFSP.lstat(path.join(normalizedCwd, candidate, ".git")).catch( () => null, ); - if (dotGit) gitRoot = candidate; + if (dotGit) nestedGitRoot = candidate; } return { - gitRoot, + nestedGitRoot, entries: children.flatMap((child, index): ProjectEntry[] => { const kind = kinds[index]; if (kind === undefined) return []; @@ -406,8 +405,8 @@ export const make = Effect.gen(function* () { }, catch: toError, }); - const gitPrefix = gitRoot ? `${gitRoot}/` : ""; - const directoryGitPath = target.relativePath.slice(gitPrefix.length); + let gitRoot = ""; + let gitPrefix = ""; // stdin avoids argument limits; ignore classification is optional without git/repositories. const checkIgnore = (paths: ReadonlyArray) => vcsProcess @@ -422,6 +421,12 @@ export const make = Effect.gen(function* () { maxOutputBytes: 16 * 1024 * 1024, }) .pipe(Effect.orElseSucceed(() => undefined)); + // Git refuses paths inside a submodule (128) but still answers for nested clones. + if (nestedGitRoot && (yield* checkIgnore([`${nestedGitRoot}/.git`]))?.exitCode === 128) { + gitRoot = nestedGitRoot; + gitPrefix = `${gitRoot}/`; + } + const directoryGitPath = target.relativePath.slice(gitPrefix.length); // Check ignored folders once to avoid child index lookups; exit 0 guarantees no tracked descendants. // Symlinks and pathspec magic still need per-child checks. if ( From 9c8ab692210bddefec163611da1337bda6b1df1f Mon Sep 17 00:00:00 2001 From: Alex Southwell <4596216+saphid@users.noreply.github.com> Date: Tue, 3 Nov 2026 10:45:13 +1100 Subject: [PATCH 3/3] fix(server): clones inside a submodule keep the submodule's ignored labels Probe each nested .git from the outermost one and move the check-ignore root only when the current repository refuses it, so a plain clone below a submodule is checked by the submodule. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/workspace/WorkspaceEntries.test.ts | 1 + apps/server/src/workspace/WorkspaceEntries.ts | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/server/src/workspace/WorkspaceEntries.test.ts b/apps/server/src/workspace/WorkspaceEntries.test.ts index a835437515e11..0acb5b62d6692 100644 --- a/apps/server/src/workspace/WorkspaceEntries.test.ts +++ b/apps/server/src/workspace/WorkspaceEntries.test.ts @@ -115,6 +115,7 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => { yield* git(cwd, ["update-index", "--add", "--cacheinfo", `160000,${gitlink},sub`]); // A nested clone that isn't a submodule keeps the outer repository's ignore rules. yield* git(cwd, ["init", "node_modules/pkg"]); + yield* git(cwd, ["init", "sub/dist"]); const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; const root = yield* workspaceEntries.list({ cwd, directoryPath: "" }); diff --git a/apps/server/src/workspace/WorkspaceEntries.ts b/apps/server/src/workspace/WorkspaceEntries.ts index 9d0f455deb9e4..d388170f93f5e 100644 --- a/apps/server/src/workspace/WorkspaceEntries.ts +++ b/apps/server/src/workspace/WorkspaceEntries.ts @@ -306,7 +306,7 @@ export const make = Effect.gen(function* () { relativePath: directoryPath, }) .pipe(Effect.mapError(toError)); - const { entries, throughSymlink, nestedGitRoot } = yield* Effect.tryPromise({ + const { entries, throughSymlink, nestedGitRoots } = yield* Effect.tryPromise({ try: async () => { const root = await NodeFSP.realpath(normalizedCwd); const directory = await NodeFSP.realpath(target.absolutePath); @@ -378,17 +378,17 @@ export const make = Effect.gen(function* () { )), ); } - let nestedGitRoot = ""; + const nestedGitRoots: Array = []; const segments = target.relativePath.split("/").filter(Boolean); - for (let index = segments.length; index > 0 && !nestedGitRoot; index -= 1) { + for (let index = 1; index <= segments.length; index += 1) { const candidate = segments.slice(0, index).join("/"); const dotGit = await NodeFSP.lstat(path.join(normalizedCwd, candidate, ".git")).catch( () => null, ); - if (dotGit) nestedGitRoot = candidate; + if (dotGit) nestedGitRoots.push(candidate); } return { - nestedGitRoot, + nestedGitRoots, entries: children.flatMap((child, index): ProjectEntry[] => { const kind = kinds[index]; if (kind === undefined) return []; @@ -422,7 +422,8 @@ export const make = Effect.gen(function* () { }) .pipe(Effect.orElseSucceed(() => undefined)); // Git refuses paths inside a submodule (128) but still answers for nested clones. - if (nestedGitRoot && (yield* checkIgnore([`${nestedGitRoot}/.git`]))?.exitCode === 128) { + for (const nestedGitRoot of nestedGitRoots) { + if ((yield* checkIgnore([`${nestedGitRoot}/.git`]))?.exitCode !== 128) continue; gitRoot = nestedGitRoot; gitPrefix = `${gitRoot}/`; }