Skip to content

Commit 9aee585

Browse files
committed
fix(server): accept CRLF in Git remote listings
1 parent 1fb8202 commit 9aee585

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,32 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
17941794
});
17951795

17961796
describe("remote operations", () => {
1797+
it.effect.each(["\n", "\r\n"])(
1798+
"ensureRemote reads remote output with %j line endings",
1799+
(ending) =>
1800+
Effect.gen(function* () {
1801+
const url = "/repos/local remote.git";
1802+
const spawner = ChildProcessSpawner.make((command) =>
1803+
Effect.sync(() => {
1804+
assert.ok(ChildProcess.isStandardCommand(command));
1805+
if (command.args.includes("rev-parse")) return makeNonRepositoryHandle();
1806+
assert.deepEqual(command.args.slice(-2), ["remote", "-v"]);
1807+
return makeSuccessfulHandle(
1808+
`origin\t${url} (fetch)${ending}origin\t${url} (push)${ending}`,
1809+
);
1810+
}),
1811+
);
1812+
const driver = yield* makeGitVcsDriverCore().pipe(
1813+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
1814+
Effect.provide(ServerConfigLayer),
1815+
);
1816+
assert.equal(
1817+
yield* driver.ensureRemote({ cwd: "/repo", preferredName: "fork", url }),
1818+
"origin",
1819+
);
1820+
}),
1821+
);
1822+
17971823
it.effect("ensureRemote preserves local remote URLs containing spaces", () =>
17981824
Effect.gen(function* () {
17991825
const cwd = yield* makeTmpDir();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ function sanitizeRemoteName(value: string): string {
305305

306306
function parseRemoteFetchUrls(stdout: string): Map<string, string> {
307307
const remotes = new Map<string, string>();
308-
for (const line of stdout.split("\n")) {
308+
for (const line of stdout.split(/\r?\n/)) {
309309
const match = /^(\S+)\t(.+) \((fetch|push)\)$/.exec(line);
310310
if (!match) continue;
311311
const [, remoteName = "", remoteUrl = "", direction = ""] = match;

0 commit comments

Comments
 (0)