@devries-cameron20 / t3code-1 / commits / 758291c176
Fork 0

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

fix(server): preserve line breaks in repository identity paths (#38114)

Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Simone committed Nov 17, 2026 at 14:06 UTC 758291c17669e0177d43ef12422a230ead47ac9d
2 files changed +19 -7
apps/server/src/project/RepositoryIdentityResolver.test.ts
+15 -4
@@ -5,6 +5,7 @@ import { expect, it } from "@effect/vitest";
5 import * as Effect from "effect/Effect";
6 import * as FileSystem from "effect/FileSystem";
7 import * as Path from "effect/Path";
8 +import * as HostProcess from "@t3tools/shared/HostProcess";
9 import { vi } from "vite-plus/test";
10
11 import * as ProcessRunner from "../processRunner.ts";
@@ -14,6 +15,14 @@ import * as RepositoryIdentityResolver from "./RepositoryIdentityResolver.ts";
15 const normalizePathSeparators = (value: string) => value.replaceAll("\\", "/");
16 const normalizeResolvedPath = (value: string) => normalizePathSeparators(value);
17
18 +// Windows forbids CR and LF in file names.
19 +const lineBreakSuffixes = HostProcess.Platform.defaultValue() === "win32" ? [] : ["\r", "\n"];
20 +const bareLayouts = [
21 + "bare clone",
22 + "dot-bare",
23 + ...lineBreakSuffixes.map((suffix) => `bare clone${suffix}`),
24 +];
25 +
26 const git = (cwd: string, args: ReadonlyArray<string>) =>
27 Effect.gen(function* () {
28 const processRunner = yield* ProcessRunner.ProcessRunner;
@@ -137,7 +146,7 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
146 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
147 );
148
140 - it.effect.each(["repo", "repo "] as const)(
149 + it.effect.each(["repo", "repo ", ...lineBreakSuffixes.map((suffix) => `repo${suffix}`)])(
150 "returns the git top-level root path when resolving from a nested workspace in %j",
151 (rootName) =>
152 Effect.gen(function* () {
@@ -167,8 +176,8 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
176 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
177 );
178
170 - it.effect.each(["bare clone", "dot-bare"] as const)(
171 - "resolves a %s to its Git directory and the same identity as a checkout",
179 + it.effect.each(bareLayouts)(
180 + "resolves a %j to its Git directory and the same identity as a checkout",
181 (layout) =>
182 Effect.gen(function* () {
183 const fileSystem = yield* FileSystem.FileSystem;
@@ -176,9 +185,11 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
185 const checkout = yield* fileSystem.makeTempDirectoryScoped({
186 prefix: "t3-repository-identity-checkout-",
187 });
179 - const root = yield* fileSystem.makeTempDirectoryScoped({
188 + const parent = yield* fileSystem.makeTempDirectoryScoped({
189 prefix: "t3-repository-identity-bare-",
190 });
191 + const root = path.join(parent, layout);
192 + yield* fileSystem.makeDirectory(root);
193 const bareGitDir = layout === "dot-bare" ? path.join(root, ".bare") : root;
194
195 yield* git(checkout, ["init"]);
apps/server/src/project/RepositoryIdentityResolver.ts
+4 -3
@@ -211,8 +211,8 @@ const resolveRepositoryIdentityCacheKey = Effect.fn("RepositoryIdentityResolver.
211 return null;
212 }
213 if (topLevelResult.value.code === 0) {
214 - // Paths may end in spaces, so strip only git's line terminator.
215 - const rootPath = topLevelResult.value.stdout.replace(/\r?\n$/, "");
214 + // Git appends LF on every platform; a preceding CR belongs to the path.
215 + const rootPath = topLevelResult.value.stdout.replace(/\n$/, "");
216 return rootPath.length > 0
217 ? new RepositoryIdentityCacheKey({ rootPath, isBare: false })
218 : null;
@@ -256,7 +256,8 @@ const resolveRepositoryIdentityCacheKey = Effect.fn("RepositoryIdentityResolver.
256 if (bareResult._tag === "None" || bareResult.value.timedOut) return null;
257 if (bareResult.value.code !== 0) continue;
258
259 - const [isBare, rootPath = ""] = bareResult.value.stdout.split(/\r?\n/);
259 + const [isBare, ...rootLines] = bareResult.value.stdout.split("\n");
260 + const rootPath = rootLines.join("\n").replace(/\n$/, "");
261 // A checkout's .git directory contains remotes but is not a project root.
262 return isBare === "true" && rootPath.length > 0
263 ? new RepositoryIdentityCacheKey({ rootPath, isBare: true })