Skip to content

Commit 9c8ab69

Browse files
saphidclaude
andcommitted
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 <[email protected]>
1 parent c167ca3 commit 9c8ab69

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎apps/server/src/workspace/WorkspaceEntries.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
115115
yield* git(cwd, ["update-index", "--add", "--cacheinfo", `160000,${gitlink},sub`]);
116116
// A nested clone that isn't a submodule keeps the outer repository's ignore rules.
117117
yield* git(cwd, ["init", "node_modules/pkg"]);
118+
yield* git(cwd, ["init", "sub/dist"]);
118119

119120
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
120121
const root = yield* workspaceEntries.list({ cwd, directoryPath: "" });

‎apps/server/src/workspace/WorkspaceEntries.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export const make = Effect.gen(function* () {
306306
relativePath: directoryPath,
307307
})
308308
.pipe(Effect.mapError(toError));
309-
const { entries, throughSymlink, nestedGitRoot } = yield* Effect.tryPromise({
309+
const { entries, throughSymlink, nestedGitRoots } = yield* Effect.tryPromise({
310310
try: async () => {
311311
const root = await NodeFSP.realpath(normalizedCwd);
312312
const directory = await NodeFSP.realpath(target.absolutePath);
@@ -378,17 +378,17 @@ export const make = Effect.gen(function* () {
378378
)),
379379
);
380380
}
381-
let nestedGitRoot = "";
381+
const nestedGitRoots: Array<string> = [];
382382
const segments = target.relativePath.split("/").filter(Boolean);
383-
for (let index = segments.length; index > 0 && !nestedGitRoot; index -= 1) {
383+
for (let index = 1; index <= segments.length; index += 1) {
384384
const candidate = segments.slice(0, index).join("/");
385385
const dotGit = await NodeFSP.lstat(path.join(normalizedCwd, candidate, ".git")).catch(
386386
() => null,
387387
);
388-
if (dotGit) nestedGitRoot = candidate;
388+
if (dotGit) nestedGitRoots.push(candidate);
389389
}
390390
return {
391-
nestedGitRoot,
391+
nestedGitRoots,
392392
entries: children.flatMap((child, index): ProjectEntry[] => {
393393
const kind = kinds[index];
394394
if (kind === undefined) return [];
@@ -422,7 +422,8 @@ export const make = Effect.gen(function* () {
422422
})
423423
.pipe(Effect.orElseSucceed(() => undefined));
424424
// Git refuses paths inside a submodule (128) but still answers for nested clones.
425-
if (nestedGitRoot && (yield* checkIgnore([`${nestedGitRoot}/.git`]))?.exitCode === 128) {
425+
for (const nestedGitRoot of nestedGitRoots) {
426+
if ((yield* checkIgnore([`${nestedGitRoot}/.git`]))?.exitCode !== 128) continue;
426427
gitRoot = nestedGitRoot;
427428
gitPrefix = `${gitRoot}/`;
428429
}

0 commit comments

Comments
 (0)