Skip to content

Commit 18fe6cf

Browse files
committed
fix(shared): preserve Azure clone addresses across protocols
1 parent 807319c commit 18fe6cf

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,21 @@ it.effect("reports both failures when the HTTPS retry fails too", () =>
321321
}),
322322
);
323323

324+
it.effect("retries an Azure SSH clone using its HTTPS host and repository path", () =>
325+
Effect.gen(function* () {
326+
const urls: Array<string> = [];
327+
const result = yield* cloneInTemporaryDirectory(rejectingSsh(urls, false), {
328+
remoteUrl: "[email protected]:v3/Fabrikam/Project1/fab_repo",
329+
});
330+
331+
assert.deepStrictEqual(urls, [
332+
"[email protected]:v3/Fabrikam/Project1/fab_repo",
333+
"https://dev.azure.com/Fabrikam/Project1/_git/fab_repo",
334+
]);
335+
assert.strictEqual(result.remoteUrl, "https://dev.azure.com/Fabrikam/Project1/_git/fab_repo");
336+
}),
337+
);
338+
324339
it.effect.each([
325340
["the caller asked for SSH", "ssh", "authentication_failed"],
326341
["git failed for another reason", undefined, "remote_unreachable"],

‎packages/shared/src/cloneUrl.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,49 @@ import { describe, expect, it } from "vite-plus/test";
33
import { cloneUrlForProtocol, cloneUrlProtocol } from "./cloneUrl.ts";
44

55
describe("cloneUrlForProtocol", () => {
6+
it.each([
7+
"[email protected]:v3/Fabrikam/Project1/fab_repo",
8+
"ssh://[email protected]/v3/Fabrikam/Project1/fab_repo",
9+
"[email protected]:v3/Fabrikam/Project1/fab_repo",
10+
])("uses Azure's HTTPS host and repository path for %s", (url) => {
11+
expect(cloneUrlForProtocol(url, "https")).toBe(
12+
"https://dev.azure.com/Fabrikam/Project1/_git/fab_repo",
13+
);
14+
});
15+
16+
it.each([
17+
"https://dev.azure.com/Fabrikam/Project1/_git/fab_repo",
18+
"https://[email protected]/Fabrikam/Project1/_git/fab_repo",
19+
"https://DEV.AZURE.COM/Fabrikam/Project1/_git/fab_repo",
20+
])("uses Azure's SSH host and repository path for %s", (url) => {
21+
expect(cloneUrlForProtocol(url, "ssh")).toBe(
22+
"[email protected]:v3/Fabrikam/Project1/fab_repo",
23+
);
24+
});
25+
26+
it("preserves encoded Azure repository components and same-protocol URLs", () => {
27+
const ssh = "[email protected]:v3/Fabrikam/Project%20One/fab%20repo";
28+
const https = "https://dev.azure.com/Fabrikam/Project%20One/_git/fab%20repo";
29+
expect(cloneUrlForProtocol(ssh, "https")).toBe(https);
30+
expect(cloneUrlForProtocol(https, "ssh")).toBe(ssh);
31+
expect(cloneUrlForProtocol(ssh, "ssh")).toBe(ssh);
32+
expect(cloneUrlForProtocol(https, "https")).toBe(https);
33+
});
34+
35+
it("refuses Azure rewrites when the project is missing or a custom port is set", () => {
36+
expect(cloneUrlForProtocol("[email protected]:v3/Fabrikam/fab_repo", "https")).toBeNull();
37+
expect(cloneUrlForProtocol("https://dev.azure.com/Fabrikam/_git/fab_repo", "ssh")).toBeNull();
38+
expect(
39+
cloneUrlForProtocol(
40+
"ssh://[email protected]:2222/v3/Fabrikam/Project1/fab_repo",
41+
"https",
42+
),
43+
).toBeNull();
44+
expect(
45+
cloneUrlForProtocol("https://dev.azure.com:8443/Fabrikam/Project1/_git/fab_repo", "ssh"),
46+
).toBeNull();
47+
});
48+
649
it("switches between scp-style SSH and HTTPS", () => {
750
expect(cloneUrlForProtocol("[email protected]:pingdotgg/t3code.git", "https")).toBe(
851
"https://github.com/pingdotgg/t3code.git",

‎packages/shared/src/cloneUrl.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ export function cloneUrlForProtocol(url: string, protocol: CloneProtocol): strin
3131
if (!parsed) return null;
3232
if (parsed.protocol === protocol) return url.trim();
3333
if (parsed.customPort) return null;
34+
// Azure's transports use different hosts and put the repository marker in
35+
// different positions; changing only the scheme produces an invalid clone URL.
36+
if (parsed.protocol === "ssh" && parsed.host.toLowerCase() === "ssh.dev.azure.com") {
37+
const azure = /^v3\/([^/]+)\/([^/]+)\/([^/]+)$/.exec(parsed.path);
38+
return azure ? `https://dev.azure.com/${azure[1]}/${azure[2]}/_git/${azure[3]}` : null;
39+
}
40+
if (parsed.protocol === "https" && parsed.host.toLowerCase() === "dev.azure.com") {
41+
const azure = /^([^/]+)\/([^/]+)\/_git\/([^/]+)$/.exec(parsed.path);
42+
return azure ? `[email protected]:v3/${azure[1]}/${azure[2]}/${azure[3]}` : null;
43+
}
3444
return protocol === "ssh"
3545
? `git@${parsed.host}:${parsed.path}`
3646
: `https://${parsed.host}/${parsed.path}`;

0 commit comments

Comments
 (0)