@devries-cameron20 / t3code Mirror · read-only / commits / e4688f7cb9
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 16:00 UTC

fix(server): find files in newline-named nested worktrees (#36588)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 14, 2026 at 10:02 UTC e4688f7cb9f265249d077f8c68ab2bd7ee0b2a13
2 files changed +35 -17
apps/server/src/workspace/WorkspaceEntries.test.ts
+13 -2
@@ -688,6 +688,13 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
688 yield* git(cwd, ["commit", "-m", "init"], env);
689 yield* git(cwd, ["worktree", "add", "-b", "x", ".worktrees/x"]);
690 yield* writeTextFile(cwd, ".worktrees/x/src/foo.py", "print(1)");
691 + const expected = [".worktrees/x/src/foo.py"];
692 + // Windows file names cannot contain a newline.
693 + if ((yield* HostProcess.Platform) !== "win32") {
694 + yield* git(cwd, ["worktree", "add", "--detach", ".worktrees/line\nname"]);
695 + yield* writeTextFile(cwd, ".worktrees/line\nname/src/foo.py", "print(2)");
696 + expected.unshift(".worktrees/line\nname/src/foo.py");
697 + }
698
699 const exact = yield* searchWorkspaceEntries({
700 cwd,
@@ -695,10 +702,14 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
702 limit: 25,
703 kind: "file",
704 });
698 - expect(exact.entries).toEqual([{ path: ".worktrees/x/src/foo.py", kind: "file" }]);
705 + expect(exact.entries.toSorted((a, b) => (a.path < b.path ? -1 : 1))).toEqual(
706 + expected.map((path) => ({ path, kind: "file" })),
707 + );
708
709 const partial = yield* searchWorkspaceEntries({ cwd, query: "src/fo", limit: 25 });
701 - expect(partial.entries.map((entry) => entry.path)).not.toContain(".worktrees/x/src/foo.py");
710 + for (const path of expected) {
711 + expect(partial.entries.map((entry) => entry.path)).not.toContain(path);
712 + }
713 }),
714 );
715 });
apps/server/src/workspace/WorkspaceEntries.ts
+22 -15
@@ -307,23 +307,30 @@ export const make = Effect.gen(function* () {
307 ) {
308 return [];
309 }
310 - const listed = yield* vcsProcess
311 - .run({
312 - operation: "WorkspaceEntries.listWorktrees",
313 - command: "git",
314 - args: ["worktree", "list", "--porcelain"],
315 - cwd,
316 - allowNonZeroExit: true,
317 - timeoutMs: 5_000,
318 - })
319 - .pipe(Effect.orElseSucceed(() => undefined));
320 - if (!listed || listed.exitCode !== 0) return [];
310 + const listWorktrees = (args: ReadonlyArray<string>) =>
311 + vcsProcess
312 + .run({
313 + operation: "WorkspaceEntries.listWorktrees",
314 + command: "git",
315 + args: ["worktree", "list", "--porcelain", ...args],
316 + cwd,
317 + allowNonZeroExit: true,
318 + timeoutMs: 5_000,
319 + })
320 + .pipe(
321 + Effect.map((result) => (result.exitCode === 0 ? result.stdout : undefined)),
322 + Effect.orElseSucceed(() => undefined),
323 + );
324 + // Only NUL framing keeps a newline in a worktree path. Pre-2.36 Git rejects `-z`.
325 + const listed =
326 + (yield* listWorktrees(["-z"])) ?? (yield* listWorktrees([]))?.replaceAll("\n", "\0");
327 + if (listed === undefined) return [];
328 const realCwd = yield* Effect.promise(() => NodeFSP.realpath(cwd).catch(() => cwd));
322 - const worktreeRoots = listed.stdout.split(/\n\s*\n/).flatMap((record) => {
323 - const lines = record.split("\n");
324 - const worktree = lines.find((line) => line.startsWith("worktree "));
329 + const worktreeRoots = listed.split("\0\0").flatMap((record) => {
330 + const fields = record.split("\0");
331 + const worktree = fields.find((field) => field.startsWith("worktree "));
332 // A `prunable` record's directory is gone; another checkout may now sit there.
326 - if (worktree === undefined || lines.some((line) => line.startsWith("prunable"))) return [];
333 + if (worktree === undefined || fields.some((field) => field.startsWith("prunable"))) return [];
334 const root = worktree.slice("worktree ".length);
335 const relativeRoot = path.relative(realCwd, root);
336 return relativeRoot === "" ||