Skip to content

Commit e55bf3e

Browse files
fix(server): repository detection handles paths containing a newline
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 411679c commit e55bf3e

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎apps/server/src/vcs/GitVcsDriver.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,24 @@ it.effect("GitVcsDriver treats a missing git executable as outside any repositor
10061006
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
10071007
);
10081008

1009+
it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
1010+
"GitVcsDriver detects a repository whose path contains a newline",
1011+
() =>
1012+
Effect.gen(function* () {
1013+
const fileSystem = yield* FileSystem.FileSystem;
1014+
const path = yield* Path.Path;
1015+
const parent = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-newline-repo-" });
1016+
const cwd = path.join(parent, "multi\nline");
1017+
yield* fileSystem.makeDirectory(cwd);
1018+
yield* runGit(cwd, ["init"]);
1019+
const driver = yield* GitVcsDriver.makeVcsDriverShape();
1020+
1021+
const repository = yield* driver.detectRepository(cwd);
1022+
assert.strictEqual(repository?.rootPath, yield* fileSystem.realPath(cwd));
1023+
assert.strictEqual(repository?.metadataPath, ".git");
1024+
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
1025+
);
1026+
10091027
it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
10101028
"GitVcsDriver still fails detection when git exists but cannot be spawned",
10111029
() =>

‎apps/server/src/vcs/GitVcsDriver.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,24 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
601601
).pipe(Effect.catchIf(isMissingExecutable, () => Effect.succeed(null)));
602602
if (result === null || result.exitCode !== 0) return null;
603603
const lines = result.stdout.replace(/\r?\n$/u, "").split(/\r?\n/u);
604-
if (lines[0]?.trim() !== "true" || lines.length !== 3) return null;
604+
if (lines[0]?.trim() !== "true") return null;
605+
// A newline inside a path breaks the line framing; ask for each path on its own.
606+
if (lines.length !== 3) {
607+
const root = yield* gitCommand(vcsProcess, "GitVcsDriver.detectRepository", cwd, [
608+
"rev-parse",
609+
"--show-toplevel",
610+
]);
611+
const gitCommonDir = yield* gitCommand(vcsProcess, "GitVcsDriver.detectRepository", cwd, [
612+
"rev-parse",
613+
"--git-common-dir",
614+
]).pipe(Effect.orElseSucceed(() => null));
615+
return {
616+
kind: "git" as const,
617+
rootPath: root.stdout.trim(),
618+
metadataPath: gitCommonDir?.stdout.trim() || null,
619+
freshness: yield* nowFreshness(),
620+
};
621+
}
605622

606623
return {
607624
kind: "git" as const,

0 commit comments

Comments
 (0)