Skip to content

Commit c167ca3

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

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
111111
yield* git(cwd, ["init", "sub"]);
112112
yield* writeTextFile(cwd, "sub/.gitignore", "dist/\n");
113113
yield* writeTextFile(cwd, "sub/dist/out.js");
114-
yield* git(cwd, ["update-index", "--add", "--cacheinfo", `160000,${"1".repeat(40)},sub`]);
114+
const gitlink = yield* git(cwd, ["hash-object", "tracked.txt"]);
115+
yield* git(cwd, ["update-index", "--add", "--cacheinfo", `160000,${gitlink},sub`]);
116+
// A nested clone that isn't a submodule keeps the outer repository's ignore rules.
117+
yield* git(cwd, ["init", "node_modules/pkg"]);
115118

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

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

Lines changed: 13 additions & 8 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, gitRoot } = yield* Effect.tryPromise({
309+
const { entries, throughSymlink, nestedGitRoot } = yield* Effect.tryPromise({
310310
try: async () => {
311311
const root = await NodeFSP.realpath(normalizedCwd);
312312
const directory = await NodeFSP.realpath(target.absolutePath);
@@ -378,18 +378,17 @@ export const make = Effect.gen(function* () {
378378
)),
379379
);
380380
}
381-
// Git refuses paths inside a submodule from the outer repository, so ask the nearest one.
382-
let gitRoot = "";
381+
let nestedGitRoot = "";
383382
const segments = target.relativePath.split("/").filter(Boolean);
384-
for (let index = segments.length; index > 0 && !gitRoot; index -= 1) {
383+
for (let index = segments.length; index > 0 && !nestedGitRoot; index -= 1) {
385384
const candidate = segments.slice(0, index).join("/");
386385
const dotGit = await NodeFSP.lstat(path.join(normalizedCwd, candidate, ".git")).catch(
387386
() => null,
388387
);
389-
if (dotGit) gitRoot = candidate;
388+
if (dotGit) nestedGitRoot = candidate;
390389
}
391390
return {
392-
gitRoot,
391+
nestedGitRoot,
393392
entries: children.flatMap((child, index): ProjectEntry[] => {
394393
const kind = kinds[index];
395394
if (kind === undefined) return [];
@@ -406,8 +405,8 @@ export const make = Effect.gen(function* () {
406405
},
407406
catch: toError,
408407
});
409-
const gitPrefix = gitRoot ? `${gitRoot}/` : "";
410-
const directoryGitPath = target.relativePath.slice(gitPrefix.length);
408+
let gitRoot = "";
409+
let gitPrefix = "";
411410
// stdin avoids argument limits; ignore classification is optional without git/repositories.
412411
const checkIgnore = (paths: ReadonlyArray<string>) =>
413412
vcsProcess
@@ -422,6 +421,12 @@ export const make = Effect.gen(function* () {
422421
maxOutputBytes: 16 * 1024 * 1024,
423422
})
424423
.pipe(Effect.orElseSucceed(() => undefined));
424+
// Git refuses paths inside a submodule (128) but still answers for nested clones.
425+
if (nestedGitRoot && (yield* checkIgnore([`${nestedGitRoot}/.git`]))?.exitCode === 128) {
426+
gitRoot = nestedGitRoot;
427+
gitPrefix = `${gitRoot}/`;
428+
}
429+
const directoryGitPath = target.relativePath.slice(gitPrefix.length);
425430
// Check ignored folders once to avoid child index lookups; exit 0 guarantees no tracked descendants.
426431
// Symlinks and pathspec magic still need per-child checks.
427432
if (

0 commit comments

Comments
 (0)