@devries-cameron20 / t3code-1 / commits / 54ad956ff2
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): file search keeps Git-ignored files a .ignore re-includes (#38337)

Julius Marminge committed Nov 17, 2026 at 13:37 UTC 54ad956ff229045bc6d9a844457426d009c10250
3 files changed +80 -32
apps/server/src/workspace/WorkspaceEntries.test.ts
+3 -3
@@ -618,7 +618,7 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
618 }
619 }),
620 );
621 - it.effect("lets the nearest .ignore rule decide a symlink, and git's rules still hide it", () =>
621 + it.effect("lets the nearest .ignore rule decide a symlink, ahead of git's rules", () =>
622 Effect.gen(function* () {
623 if ((yield* HostProcess.Platform) === "win32") return;
624 const cwd = yield* makeTempDir({ prefix: "t3code-workspace-symlinks-", git: true });
@@ -639,12 +639,12 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
639 for (const entries of [searched.entries, listed.entries]) {
640 const paths = entries.map((entry) => entry.path);
641 expect(paths).toContain("sub/hide-link.ts");
642 - expect(paths).not.toContain("keep-link.ts");
642 + expect(paths).toContain("keep-link.ts");
643 }
644 // The real files are shown or hidden by the same rules.
645 const listedPaths = listed.entries.map((entry) => entry.path);
646 expect(listedPaths).toContain("sub/hide-real.ts");
647 - expect(listedPaths).not.toContain("keep-real.ts");
647 + expect(listedPaths).toContain("keep-real.ts");
648 }),
649 );
650 it.effect("matches .ignore rules against whole names and treats folder links as links", () =>
apps/server/src/workspace/WorkspaceSearchIndex.test.ts
+24
@@ -748,3 +748,27 @@ it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
748 }),
749 ).pipe(Effect.provide(testLayer)),
750 );
751 +
752 +// ripgrep and fff let a matching `.ignore` decide ahead of `.gitignore`, so Git's list must not hide it.
753 +it.live("finds Git-ignored files that a root .ignore re-includes", () =>
754 + Effect.gen(function* () {
755 + const fileSystem = yield* FileSystem.FileSystem;
756 + const path = yield* Path.Path;
757 + const vcsProcess = yield* VcsProcess.VcsProcess;
758 + const cwd = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-search-reinclude-" });
759 + yield* vcsProcess.run({ operation: "test.gitInit", command: "git", args: ["init"], cwd });
760 + yield* fileSystem.writeFileString(path.join(cwd, ".gitignore"), "notes/\n");
761 + yield* fileSystem.writeFileString(
762 + path.join(cwd, ".ignore"),
763 + "!notes/\nnotes/**/*\n!notes/**/\n!notes/**/*.md\n",
764 + );
765 + yield* fileSystem.makeDirectory(path.join(cwd, "notes", "daily"), { recursive: true });
766 + yield* fileSystem.writeFileString(path.join(cwd, "notes", "daily", "standup.md"), "");
767 + yield* fileSystem.writeFileString(path.join(cwd, "notes", "daily", "standup.txt"), "");
768 +
769 + const searchIndex = yield* WorkspaceSearchIndex.make(cwd);
770 + const result = yield* searchIndex.search("standup", 50, "file");
771 +
772 + expect(result.entries).toEqual([{ kind: "file", path: "notes/daily/standup.md" }]);
773 + }).pipe(Effect.scoped, Effect.provide(testLayer)),
774 +);
apps/server/src/workspace/WorkspaceSearchIndex.ts
+53 -29
@@ -526,13 +526,12 @@ const listGitIgnoredPaths = Effect.fn("WorkspaceSearchIndex.listGitIgnoredPaths"
526 maxOutputBytes: 16 * 1024 * 1024,
527 })
528 .pipe(Effect.orElseSucceed(() => undefined));
529 - if (!result || result.exitCode !== 0 || result.stdoutTruncated) return new Set<string>();
530 - return new Set(
531 - result.stdout
532 - .split("\0")
533 - .filter((entry) => entry.length > 0)
534 - .map((entry) => trimDirectorySeparator(toPosixPath(entry, hostIsWindows))),
535 - );
529 + if (!result || result.exitCode !== 0 || result.stdoutTruncated) return [];
530 + // Folders keep their trailing `/`.
531 + return result.stdout
532 + .split("\0")
533 + .filter((entry) => entry.length > 0)
534 + .map((entry) => toPosixPath(entry, hostIsWindows));
535 });
536
537 function mixedItemPath(item: MixedItem): string {
@@ -624,7 +623,50 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
623 // so content searches do not wait for it; git grep answers until it is ready.
624 let contentIndexPending = variant === "content";
625 const vcsProcess = yield* VcsProcess.VcsProcess;
627 - let ignoredPaths = yield* listGitIgnoredPaths(vcsProcess, cwd, hostIsWindows);
626 +
627 + /** The nearest `.ignore` with a pattern matching `relativePath` itself decides. */
628 + const makeIgnoreFileDecider = () => {
629 + const ignoreFiles = new Map<string, IgnoreFile | undefined>();
630 + const readIgnoreFile = Effect.fn("WorkspaceSearchIndex.readIgnoreFile")(function* (
631 + directory: string,
632 + ) {
633 + if (ignoreFiles.has(directory)) return ignoreFiles.get(directory);
634 + const contents = yield* fileSystem
635 + .readFileString(path.join(cwd, directory, ".ignore"))
636 + .pipe(Effect.option);
637 + const file = Option.isSome(contents) ? parseIgnoreFile(contents.value) : undefined;
638 + ignoreFiles.set(directory, file);
639 + return file;
640 + });
641 + return Effect.fn("WorkspaceSearchIndex.decideByIgnoreFile")(function* (
642 + relativePath: string,
643 + isFolder: boolean,
644 + ) {
645 + const segments = relativePath.split("/");
646 + for (let ancestor = segments.length - 1; ancestor >= 0; ancestor -= 1) {
647 + const directory = segments.slice(0, ancestor).join("/");
648 + const file = yield* readIgnoreFile(directory);
649 + const relative = directory ? relativePath.slice(directory.length + 1) : relativePath;
650 + const decision = file?.decide(relative, isFolder);
651 + if (decision) return decision;
652 + }
653 + return undefined;
654 + });
655 + };
656 +
657 + // Like ripgrep and fff, a `.ignore` that re-includes a path overrules Git's ignore rules for it.
658 + const loadIgnoredPaths = Effect.fn("WorkspaceSearchIndex.loadIgnoredPaths")(function* () {
659 + const decide = makeIgnoreFileDecider();
660 + const ignored = new Set<string>();
661 + for (const entry of yield* listGitIgnoredPaths(vcsProcess, cwd, hostIsWindows)) {
662 + const relativePath = trimDirectorySeparator(entry);
663 + if ((yield* decide(relativePath, entry.endsWith("/"))) !== "included") {
664 + ignored.add(relativePath);
665 + }
666 + }
667 + return ignored;
668 + });
669 + let ignoredPaths = yield* loadIgnoredPaths();
670 if (variant === "paths") {
671 yield* waitForIndexReady(
672 cwd,
@@ -713,32 +755,14 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
755 // fff leaves out what `.ignore` files exclude, which git cannot evaluate; the nearest
756 // `.ignore` that matches a path or one of its folders decides, as in decideByIgnoreFiles.
757 const makeIgnoreFileFilter = () => {
716 - const ignoreFiles = new Map<string, IgnoreFile | undefined>();
717 - const readIgnoreFile = Effect.fn("WorkspaceSearchIndex.readIgnoreFile")(function* (
718 - directory: string,
719 - ) {
720 - if (ignoreFiles.has(directory)) return ignoreFiles.get(directory);
721 - const contents = yield* fileSystem
722 - .readFileString(path.join(cwd, directory, ".ignore"))
723 - .pipe(Effect.option);
724 - const file = Option.isSome(contents) ? parseIgnoreFile(contents.value) : undefined;
725 - ignoreFiles.set(directory, file);
726 - return file;
727 - });
758 + const decide = makeIgnoreFileDecider();
759 return Effect.fn("WorkspaceSearchIndex.isExcludedByIgnoreFiles")(function* (
760 relativePath: string,
761 ) {
762 const segments = relativePath.split("/");
763 for (let depth = 1; depth <= segments.length; depth += 1) {
764 const candidate = segments.slice(0, depth).join("/");
734 - for (let ancestor = depth - 1; ancestor >= 0; ancestor -= 1) {
735 - const directory = segments.slice(0, ancestor).join("/");
736 - const file = yield* readIgnoreFile(directory);
737 - const relative = directory ? candidate.slice(directory.length + 1) : candidate;
738 - const decision = file?.decide(relative, depth < segments.length);
739 - if (decision === "ignored") return true;
740 - if (decision === "included") break;
741 - }
765 + if ((yield* decide(candidate, depth < segments.length)) === "ignored") return true;
766 }
767 return false;
768 });
@@ -1159,7 +1183,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
1183 cause,
1184 }),
1185 ).pipe(Effect.catchTags({ WorkspaceSearchIndexScanTimedOut: () => Effect.void }));
1162 - ignoredPaths = yield* listGitIgnoredPaths(vcsProcess, cwd, hostIsWindows);
1186 + ignoredPaths = yield* loadIgnoredPaths();
1187 invalidateSymlinkScan();
1188 });
1189