diff --git a/src/features/agents/SessionAssets.test.tsx b/src/features/agents/SessionAssets.test.tsx index 2fa4b037a..33f8352d1 100644 --- a/src/features/agents/SessionAssets.test.tsx +++ b/src/features/agents/SessionAssets.test.tsx @@ -229,7 +229,9 @@ describe("SessionAssets component", () => { vi.spyOn(ipc, "call").mockImplementation(async (promise) => { return promise; }); - vi.spyOn(ipc.commands, "vcsConfigGet").mockResolvedValue("git@github-personal:acme/monorepo.git" as never); + vi.spyOn(ipc.commands, "vcsRemotes").mockResolvedValue([ + { name: "origin", url: "git@github-personal:acme/monorepo.git" }, + ] as never); vi.spyOn(ipc.commands, "ghPrList").mockResolvedValue([branchSummary] as never); vi.spyOn(ipc.commands, "ghApi").mockImplementation((_repo, req) => { if (req.endpoint === "repos/acme/monorepo/pulls/122518") { diff --git a/src/features/agents/SessionAssets.tsx b/src/features/agents/SessionAssets.tsx index 58f8dd607..1358f3abc 100644 --- a/src/features/agents/SessionAssets.tsx +++ b/src/features/agents/SessionAssets.tsx @@ -204,13 +204,15 @@ export function SessionAssets({ task, entries, head, onFocusComposer }: SessionA const refsAnchor = useRef(null); const artifactsAnchor = useRef(null); - // Read `remote.origin.url` so `gh pr checks 123` / `gh issue view 456` resolve to `/`. + // Read `origin` (with any `~/.ssh/config` host alias resolved) so `gh pr checks 123` / + // `gh issue view 456` resolve to `/`. useEffect(() => { if (!isTauri()) return; let alive = true; - call(commands.vcsConfigGet(repoRoot, "remote.origin.url")) - .then((url) => { - if (alive) setRemoteUrl(url || null); + call(commands.vcsRemotes(repoRoot)) + .then((remotes) => { + const origin = remotes.find((r) => r.name === "origin"); + if (alive) setRemoteUrl(origin ? (origin.resolvedUrl ?? origin.url) : null); }) .catch(() => { if (alive) setRemoteUrl(null); diff --git a/src/features/vcs/__tests__/copyRemoteLink.test.ts b/src/features/vcs/__tests__/copyRemoteLink.test.ts index eb2d8e98e..4aae6c951 100644 --- a/src/features/vcs/__tests__/copyRemoteLink.test.ts +++ b/src/features/vcs/__tests__/copyRemoteLink.test.ts @@ -6,6 +6,7 @@ import type { MenuItem } from "@/ui"; const config = vi.hoisted(() => new Map()); const configReads = vi.hoisted(() => vi.fn()); +const remotes = vi.hoisted(() => new Map()); vi.mock("@/platform/ipc", async (importOriginal) => { const real = await importOriginal(); @@ -14,6 +15,7 @@ vi.mock("@/platform/ipc", async (importOriginal) => { call: vi.fn(async (request: Promise) => request), commands: { ...real.commands, + vcsRemotes: async (root: string) => remotes.get(root) ?? [], vcsConfigGet: async (root: string, key: string) => { configReads(root, key); return config.get(`${root} ${key}`) ?? null; @@ -42,6 +44,7 @@ async function start() { beforeEach(() => { vi.clearAllMocks(); config.clear(); + remotes.clear(); config.set("/p remote.origin.url", "git@gitlab.example.com:group/sub/app.git"); vi.stubGlobal("navigator", { clipboard: { writeText }, userAgent: navigator.userAgent }); provideNotificationService({ notify }); @@ -113,6 +116,17 @@ describe("Copy Path/Reference… › Link", () => { expect(items({ paths: ["/p/a.ts"] })).toEqual([]); }); + it("builds the link on the web host behind an ~/.ssh/config host alias", async () => { + remotes.set("/p", [ + { name: "origin", url: "git@github.com-work:acme/app.git", resolvedUrl: "git@github.com:acme/app.git" }, + ]); + await start(); + expect(items({ paths: ["/p/src/main.rs"], line: 9 })[0]).toMatchObject({ + label: "GitHub Link", + preview: "https://github.com/acme/app/blob/feature/x/src/main.rs#L10", + }); + }); + it("warns instead of copying when the file has no page on a remote", async () => { await executeAction("vcs.copyRemoteLink", { path: "/elsewhere/a.ts", line: 0 }); await vi.waitFor(() => diff --git a/src/features/vcs/historyActions.tsx b/src/features/vcs/historyActions.tsx index 1de40fdd8..0344ed04f 100644 --- a/src/features/vcs/historyActions.tsx +++ b/src/features/vcs/historyActions.tsx @@ -13,6 +13,7 @@ import { executeAction, registerActions, type Action } from "@/platform/actions" import { checkoutDetached, newBranch, rebaseOnto } from "./branchOps"; import { openUrl } from "./issueLinks"; import { commitWebUrl } from "./model"; +import { remoteWebSource } from "./remoteUrl"; import { commitChangelist, deleteChangelist, @@ -156,7 +157,7 @@ function withCommits(fn: (cs: Commit[]) => unknown, allowReadOnly = false) { async function openCommitInBrowser(c: Commit) { const upstream = useVcs.getState().branch?.upstream; const remote = upstream ? upstream.slice(0, upstream.indexOf("/")) : "origin"; - const url = await call(commands.vcsConfigGet(currentRepo(), `remote.${remote}.url`)).catch(() => null); + const url = await remoteWebSource(currentRepo(), remote); const page = url ? commitWebUrl(url, c.id) : null; if (page) await openUrl(page); else notifications().notify({ group: "vcs", level: "warning", title: `No web URL for remote '${remote}'` }); diff --git a/src/features/vcs/openOnRemote.ts b/src/features/vcs/openOnRemote.ts index 7d7f17cdd..5d7a5b810 100644 --- a/src/features/vcs/openOnRemote.ts +++ b/src/features/vcs/openOnRemote.ts @@ -3,13 +3,13 @@ * of its repository's remote, at the current branch's upstream (else the HEAD commit). * Copy Path/Reference… › Link copies that page's address, with the selected lines. */ -import { call, commands } from "@/platform/ipc"; import { executeAction, type Action } from "@/platform/actions"; import { writeClipboardText } from "@/platform/clipboard"; import { tx } from "@/platform/i18n"; import { notifications, registerMenuGroup } from "@/workbench/contributions"; import { openUrl } from "./issueLinks"; import { fileWebUrl, remoteHosting, rootOf } from "./model"; +import { remoteWebSource } from "./remoteUrl"; import { useVcs } from "./store"; interface Target { @@ -30,9 +30,9 @@ function remoteName(root: string): string { } async function readRemoteUrl(root: string): Promise { - const url = await call(commands.vcsConfigGet(root, `remote.${remoteName(root)}.url`)).catch(() => null); - remoteUrls.set(root, url || null); - return url || null; + const url = await remoteWebSource(root, remoteName(root)); + remoteUrls.set(root, url); + return url; } function revision(root: string): string | null { diff --git a/src/features/vcs/remoteUrl.ts b/src/features/vcs/remoteUrl.ts new file mode 100644 index 000000000..13fc04bc9 --- /dev/null +++ b/src/features/vcs/remoteUrl.ts @@ -0,0 +1,12 @@ +import { call, commands } from "@/platform/ipc"; + +/** + * The URL web pages of `remote` in `repo` are built from: its fetch URL with any `~/.ssh/config` + * host alias resolved (`git@github.com-work:o/r` → `git@github.com:o/r`). Null without that remote. + */ +export async function remoteWebSource(repo: string | null, remote: string): Promise { + const remotes = await call(commands.vcsRemotes(repo)).catch(() => null); + const found = remotes?.find((r) => r.name === remote); + if (found) return found.resolvedUrl ?? found.url; + return (await call(commands.vcsConfigGet(repo, `remote.${remote}.url`)).catch(() => null)) || null; +}