Skip to content

Commit 3969ac0

Browse files
committed
fix(server): keep pathless clone query tokens out of errors
1 parent 6e9c8a6 commit 3969ac0

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎apps/server/src/sourceControl/SourceControlRepositoryService.test.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,15 @@ it.effect.each([
397397
{
398398
execute: (input) =>
399399
Effect.gen(function* () {
400-
// Git quotes the URL it was given, query included, and appends a slash.
400+
const cloneUrl = input.args.at(-2)!;
401+
// Git treats @ in a pathless URL's query as userinfo, losing the query delimiter.
402+
const diagnosticUrl =
403+
cloneUrl === "https://github.com?access_token=abc@secret"
404+
? "https://secret"
405+
: cloneUrl;
401406
yield* (
402407
input.progress?.onStderrLine?.(
403-
`fatal: unable to access '${remote}?access_token=${token}/': Could not resolve host: github.com`,
408+
`fatal: unable to access '${diagnosticUrl}/': Could not resolve host: github.com`,
404409
) ?? Effect.void
405410
);
406411
return yield* new GitCommandError({
@@ -418,7 +423,7 @@ it.effect.each([
418423

419424
assert.strictEqual(
420425
error.detail,
421-
`fatal: unable to access '${remote}': Could not resolve host: github.com`,
426+
`fatal: unable to access '${remote}${token === "abc@secret" ? "/" : ""}': Could not resolve host: github.com`,
422427
);
423428
}),
424429
);

‎apps/server/src/sourceControl/SourceControlRepositoryService.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,13 @@ export const make = Effect.gen(function* () {
346346
if (stderrTail.length > 4) stderrTail.shift();
347347
});
348348
};
349+
// Git misreads @ in a pathless URL's query as userinfo and echoes its suffix as the host.
350+
const normalizedCloneUrl = cloneUrl.replace(/^([a-z][a-z0-9+.-]*:\/\/[^/?#]+)\?/i, "$1/?");
349351
yield* git
350352
.execute({
351353
operation: "SourceControlRepositoryService.cloneRepository",
352354
cwd: path.dirname(destinationPath),
353-
args: ["clone", "--progress", "--", cloneUrl, path.basename(destinationPath)],
355+
args: ["clone", "--progress", "--", normalizedCloneUrl, path.basename(destinationPath)],
354356
timeoutMs: options?.timeoutMs === undefined ? CLONE_TIMEOUT_MS : options.timeoutMs,
355357
// Buffered output is unused and progress can be huge; cap it while retaining line callbacks.
356358
maxOutputBytes: 256 * 1024,

0 commit comments

Comments
 (0)