diff --git a/src/features/vcs/__tests__/fileWebUrl.test.ts b/src/features/vcs/__tests__/fileWebUrl.test.ts index 6b3e0138c..a6ea504f3 100644 --- a/src/features/vcs/__tests__/fileWebUrl.test.ts +++ b/src/features/vcs/__tests__/fileWebUrl.test.ts @@ -7,6 +7,8 @@ describe("remoteHosting", () => { ["https://github.example.com/o/r", "GitHub", "github"], ["https://gitee.com/o/r.git", "Gitee", "github"], ["git@bitbucket.org:o/r.git", "Bitbucket", "bitbucket"], + ["git@ssh.bitbucket.org:team/repo.git", "Bitbucket", "bitbucket"], + ["git@ssh.github.com:o/r.git", "GitHub", "github"], ["ssh://git@gitlab.example.com:2222/group/sub/r.git", "GitLab", "gitlab"], ["git@git.example.com:group/r.git", "git.example.com", "gitlab"], ])("%s → %s", (url, name, kind) => { @@ -43,4 +45,10 @@ describe("fileWebUrl", () => { "https://bitbucket.org/o/r/src/main/a.py#lines-5", ); }); + + it("opens a Bitbucket Cloud SSH clone on bitbucket.org, not the SSH front host (#3372)", () => { + expect(fileWebUrl("git@ssh.bitbucket.org:team/repo.git", "main", "a.py", { line: 4 })).toBe( + "https://bitbucket.org/team/repo/src/main/a.py#lines-5", + ); + }); }); diff --git a/src/features/vcs/model.ts b/src/features/vcs/model.ts index 9e82e02e4..ce3d69052 100644 --- a/src/features/vcs/model.ts +++ b/src/features/vcs/model.ts @@ -139,6 +139,13 @@ export function stashLabel(message: string): { branch: string | null; text: stri return { branch: m[1]!, text: m[2]!.trim() || message }; } +/** SSH front hosts that serve the same service as the web host in the value. */ +const WEB_HOST_ALIASES: Record = { + "ssh.bitbucket.org": "bitbucket.org", + "ssh.github.com": "github.com", + "altssh.gitlab.com": "gitlab.com", +}; + /** * Web page of a git remote URL (`git@github.com:o/r.git`, `ssh://git@host:22/o/r`, * `https://user@host/o/r.git`), or null for local paths. @@ -155,6 +162,7 @@ export function remoteWebUrl(url: string): string | null { if (full) [, host, path] = full as unknown as [string, string, string]; else if (scp) [, host, path] = scp as unknown as [string, string, string]; else return null; + host = WEB_HOST_ALIASES[host.toLowerCase()] ?? host; return `https://${host}/${path.replace(/^\/+/, "")}`; }