Skip to content

Commit d7afa37

Browse files
committed
fix(server): a wide folder named like a glob is classified by git, not assumed ignored
check-ignore reads each path as a pathspec, so a folder such as [id] can match tracked files elsewhere and git answers differently per child. Such folders now take the per-child path.
1 parent 78704ad commit d7afa37

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,42 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
158158
}),
159159
);
160160

161+
it.effect("labels a glob-named directory's children as git does for each child", () =>
162+
Effect.gen(function* () {
163+
const cwd = yield* makeTempDir({ git: true });
164+
yield* writeTextFile(cwd, ".gitignore", "\\[id\\]/\n");
165+
yield* writeTextFile(cwd, "i/page.tsx");
166+
yield* git(cwd, ["add", ".gitignore", "i/page.tsx"]);
167+
yield* writeWideDirectory(cwd, "[id]");
168+
yield* writeTextFile(cwd, "[id]/page.tsx");
169+
170+
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
171+
const listing = yield* workspaceEntries.list({ cwd, directoryPath: "[id]" });
172+
173+
// `check-ignore` reads each path as a pathspec, so `[id]/page.tsx` matches the tracked
174+
// `i/page.tsx` and is not reported as ignored. Ask git per child for the answer.
175+
const vcsProcess = yield* VcsProcess.VcsProcess;
176+
const childPaths = listing.entries.map((entry) => entry.path);
177+
const answer = yield* vcsProcess.run({
178+
operation: "WorkspaceEntries.test.checkIgnore",
179+
command: "git",
180+
args: ["check-ignore", "-z", "--stdin"],
181+
cwd,
182+
stdin: `${childPaths.join("\0")}\0`,
183+
allowNonZeroExit: true,
184+
timeoutMs: 10_000,
185+
});
186+
const expectedIgnored = new Set(answer.stdout.split("\0").filter(Boolean));
187+
188+
expect(childPaths).toHaveLength(WIDE + 1);
189+
expect(expectedIgnored.has("[id]/pkg-0.js")).toBe(true);
190+
expect(expectedIgnored.has("[id]/page.tsx")).toBe(false);
191+
expect(
192+
new Set(listing.entries.filter((entry) => entry.ignored).map((entry) => entry.path)),
193+
).toEqual(expectedIgnored);
194+
}),
195+
);
196+
161197
it.effect("keeps a force-tracked file and a directory with tracked files unignored", () =>
162198
Effect.gen(function* () {
163199
const cwd = yield* makeTempDir({ git: true });

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,13 @@ export const make = Effect.gen(function* () {
344344
// Git consults the index for every path it classifies, which costs hundreds of
345345
// milliseconds for a `node_modules`-sized folder. An ignored directory hides all of its
346346
// children, so when nothing under it is tracked they are all ignored without asking.
347+
// `check-ignore` reads each path as a pathspec, so a folder like `[id]` can match tracked
348+
// files elsewhere and git then answers differently per child; those folders ask git.
347349
const wholeDirectoryIgnored =
348350
entries.length > IGNORE_CHECK_CHUNK_SIZE &&
349351
target.relativePath !== "" &&
350352
!throughSymlink &&
353+
!/[*?[\\]/.test(target.relativePath) &&
351354
(yield* Effect.gen(function* () {
352355
const directory = yield* runGit(
353356
["check-ignore", "-z", "--stdin"],

0 commit comments

Comments
 (0)