Skip to content

Commit 5fbccae

Browse files
committed
fix(server): preserve spaces in Git remote URLs
1 parent faa8ad6 commit 5fbccae

4 files changed

Lines changed: 109 additions & 40 deletions

File tree

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

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -102,35 +102,54 @@ runVcsDriverContractSuite<GitVcsDriver.GitVcsDriver, GitContractError>({
102102
},
103103
});
104104

105-
it.effect("lists the fetch and push URLs of a partial clone remote", () =>
106-
Effect.gen(function* () {
107-
const fileSystem = yield* FileSystem.FileSystem;
108-
const cwd = yield* fileSystem.makeTempDirectoryScoped({
109-
prefix: "t3-partial-clone-remotes-",
110-
});
111-
const driver = yield* GitVcsDriver.makeVcsDriverShape();
112-
yield* runGit(cwd, ["init"]);
113-
yield* runGit(cwd, ["remote", "add", "origin", "https://github.com/pingdotgg/t3code.git"]);
114-
yield* runGit(cwd, [
115-
"remote",
116-
"set-url",
117-
"--push",
118-
"origin",
119-
"[email protected]:octocat/t3code.git",
120-
]);
121-
yield* runGit(cwd, ["config", "remote.origin.promisor", "true"]);
122-
yield* runGit(cwd, ["config", "remote.origin.partialclonefilter", "blob:none"]);
123-
124-
const result = yield* driver.listRemotes(cwd);
125-
assert.deepEqual(result.remotes, [
126-
{
127-
name: "origin",
128-
url: "https://github.com/pingdotgg/t3code.git",
129-
pushUrl: Option.some("[email protected]:octocat/t3code.git"),
130-
isPrimary: true,
131-
},
132-
]);
133-
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
105+
it.effect.each([
106+
{
107+
fetchUrl: "https://github.com/pingdotgg/t3code.git",
108+
pushUrl: "[email protected]:octocat/t3code.git",
109+
lineEnding: "\n",
110+
},
111+
{ fetchUrl: "../team repos/shared.git", pushUrl: "../team repos/push.git", lineEnding: "\n" },
112+
{
113+
fetchUrl: " ../team repos/shared (fetch) [blob:none].git ",
114+
pushUrl: "../team repos/push (push).git\t",
115+
lineEnding: "\r\n",
116+
},
117+
])(
118+
"lists the fetch and push URLs of a partial clone remote (%j)",
119+
({ fetchUrl, pushUrl, lineEnding }) =>
120+
Effect.gen(function* () {
121+
const fileSystem = yield* FileSystem.FileSystem;
122+
const cwd = yield* fileSystem.makeTempDirectoryScoped({
123+
prefix: "t3-partial-clone-remotes-",
124+
});
125+
const process = yield* VcsProcess.VcsProcess;
126+
const driver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
127+
Effect.provideService(VcsProcess.VcsProcess, {
128+
run: (input) =>
129+
process.run(input).pipe(
130+
Effect.map((result) => ({
131+
...result,
132+
stdout: result.stdout.replace(/\r?\n/g, lineEnding),
133+
})),
134+
),
135+
}),
136+
);
137+
yield* runGit(cwd, ["init"]);
138+
yield* runGit(cwd, ["remote", "add", "origin", fetchUrl]);
139+
yield* runGit(cwd, ["remote", "set-url", "--push", "origin", pushUrl]);
140+
yield* runGit(cwd, ["config", "remote.origin.promisor", "true"]);
141+
yield* runGit(cwd, ["config", "remote.origin.partialclonefilter", "blob:none"]);
142+
143+
const result = yield* driver.listRemotes(cwd);
144+
assert.deepEqual(result.remotes, [
145+
{
146+
name: "origin",
147+
url: fetchUrl,
148+
pushUrl: Option.some(pushUrl),
149+
isPrimary: true,
150+
},
151+
]);
152+
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
134153
);
135154

136155
const makeCheckpointFixture = Effect.fn("makeCheckpointFixture")(function* (

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,10 @@ function parseGitRemoteVerboseOutput(
518518
output: string,
519519
): Map<string, { url?: string; pushUrl?: string }> {
520520
const remotes = new Map<string, { url?: string; pushUrl?: string }>();
521-
for (const line of output.split("\n")) {
522-
const trimmed = line.trim();
523-
if (trimmed.length === 0) {
524-
continue;
525-
}
526-
521+
for (const line of output.split(/\r?\n/)) {
522+
// Git uses a tab before the URL and one space before the direction; both can occur in URLs.
527523
// Partial clones append the promisor filter, e.g. `(fetch) [blob:none]`.
528-
const match = /^(\S+)\s+(\S+)\s+\((fetch|push)\)(?:\s+\[[^\]]+\])?$/.exec(trimmed);
524+
const match = /^(\S+)\t(.+) \((fetch|push)\)(?:\s+\[[^\]]+\])?$/.exec(line);
529525
if (!match) {
530526
continue;
531527
}

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5593,6 +5593,61 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
55935593
}),
55945594
);
55955595

5596+
it.effect.each(["\n", "\r\n"])(
5597+
"ensureRemote preserves spaces in fetch URLs and reserves their names (%j)",
5598+
(lineEnding) =>
5599+
Effect.gen(function* () {
5600+
const cwd = yield* makeTmpDir();
5601+
const fetchUrl = " ../team repos/shared (fetch) [blob:none].git ";
5602+
const pushUrl = "../team repos/push (push).git";
5603+
yield* git(cwd, ["init"]);
5604+
yield* git(cwd, ["remote", "add", "origin", fetchUrl]);
5605+
yield* git(cwd, ["remote", "set-url", "--push", "origin", pushUrl]);
5606+
yield* git(cwd, ["config", "remote.origin.promisor", "true"]);
5607+
yield* git(cwd, ["config", "remote.origin.partialclonefilter", "blob:none"]);
5608+
const liveDriver = yield* GitVcsDriver.GitVcsDriver;
5609+
const listing = yield* liveDriver.execute({
5610+
cwd,
5611+
args: ["remote", "-v"],
5612+
operation: "test",
5613+
});
5614+
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
5615+
const spawner = ChildProcessSpawner.make((command) =>
5616+
ChildProcess.isStandardCommand(command) &&
5617+
command.args[0] === "remote" &&
5618+
command.args[1] === "-v"
5619+
? Effect.succeed(makeSuccessfulHandle(listing.stdout.replace(/\r?\n/g, lineEnding)))
5620+
: delegate.spawn(command),
5621+
);
5622+
const driver = yield* makeGitVcsDriverCore().pipe(
5623+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
5624+
Effect.provide(layerServerConfig),
5625+
);
5626+
5627+
assert.equal(
5628+
yield* driver.ensureRemote({ cwd, preferredName: "origin", url: fetchUrl }),
5629+
"origin",
5630+
);
5631+
assert.equal(
5632+
yield* driver.ensureRemote({ cwd, preferredName: "origin", url: pushUrl }),
5633+
"origin-1",
5634+
);
5635+
const fetch = yield* liveDriver.execute({
5636+
cwd,
5637+
args: ["config", "--get", "remote.origin.url"],
5638+
operation: "test",
5639+
});
5640+
const push = yield* liveDriver.execute({
5641+
cwd,
5642+
args: ["config", "--get", "remote.origin.pushurl"],
5643+
operation: "test",
5644+
});
5645+
assert.equal(fetch.stdout, `${fetchUrl}\n`);
5646+
assert.equal(push.stdout, `${pushUrl}\n`);
5647+
assert.equal(yield* git(cwd, ["config", "--get", "remote.origin-1.url"]), pushUrl);
5648+
}),
5649+
);
5650+
55965651
it.effect("ensureRemote returns the remote a parallel call added for the same URL", () =>
55975652
Effect.gen(function* () {
55985653
const cwd = yield* makeTmpDir();

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,10 @@ function sanitizeRemoteName(value: string): string {
350350

351351
function parseRemoteFetchUrls(stdout: string): Map<string, string> {
352352
const remotes = new Map<string, string>();
353-
for (const line of stdout.split("\n")) {
354-
const trimmed = line.trim();
355-
if (trimmed.length === 0) continue;
353+
for (const line of stdout.split(/\r?\n/)) {
354+
// Git uses a tab before the URL and one space before the direction; both can occur in URLs.
356355
// Partial clones append the promisor filter, e.g. `(fetch) [blob:none]`.
357-
const match = /^(\S+)\s+(\S+)\s+\((fetch|push)\)(?:\s+\[[^\]]+\])?$/.exec(trimmed);
356+
const match = /^(\S+)\t(.+) \((fetch|push)\)(?:\s+\[[^\]]+\])?$/.exec(line);
358357
if (!match) continue;
359358
const [, remoteName = "", remoteUrl = "", direction = ""] = match;
360359
if (direction !== "fetch" || remoteName.length === 0 || remoteUrl.length === 0) {

0 commit comments

Comments
 (0)