fix(github): keep a new pull request's head on the base repository's host (#6746)

Follow-up to #6742. The new pull request form's head repository picker keyed its options by owner/name, so same-named repositories on an Enterprise server and on github.com could not both be picked, and it offered remotes on another host. It now lists only remotes on the base repository's host, keyed by host/owner/name, and the default head ignores a tracked remote on another host. A selection saved before #6742 (no host) now resolves to the origin remote's repository when that is one of the matches, instead of depending on remote order.

Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-11-28 23:04:41 +08:00
1 джерело 836a4405d6
коміт 9aa0718cf9
6 files changed
+79 -11

No files matched your search

+7
Переглянути файл
@@ -434,6 +434,13 @@ describe("pull request helpers", () => {
])
expect(parseGitHubRemote(url, hosts), url).toEqual({ owner: "acme", name: "app", host: "ghe.example.com" });
expect(parseGitHubRemote("https://ghe.example.com/acme/app.git")).toBeNull();
// gh names a server on another port `host:port`; its remotes match whatever port they use.
for (const url of ["https://ghe.example.com:8443/acme/app.git", "[email protected]:acme/app.git"])
expect(parseGitHubRemote(url, ["ghe.example.com:8443"]), url).toEqual({
owner: "acme",
name: "app",
host: "ghe.example.com:8443",
});
expect(parseGitHubRemote("https://gheXexample.com/acme/app.git", hosts)).toBeNull();
expect(
githubRemotes(
+31 -2
Переглянути файл
@@ -27,7 +27,15 @@ vi.mock("@/platform/ipc", () => ({
import { useProject } from "@/platform/project";
import { rest } from "../api/client";
import { connectedRoot, connectedRemotes, connect, disconnect, refreshConnection, useGhRepository } from "./repository";
import {
connectedRoot,
connectedRemotes,
connect,
disconnect,
refreshConnection,
resetConnection,
useGhRepository,
} from "./repository";
afterEach(() => {
ghApi.mockReset();
@@ -35,6 +43,7 @@ afterEach(() => {
localStorage.clear();
layout = FOLDER;
useProject.setState({ project: null });
resetConnection();
});
describe("a folder holding several git repositories", () => {
@@ -158,16 +167,36 @@ describe("GitHub Enterprise Server hosts beside github.com", () => {
expect(ghApi).toHaveBeenLastCalledWith("/w/app", expect.objectContaining({ host: "ghe.example.com" }));
});
it("reads a choice saved without a host as the origin remote's repository", async () => {
layout = {
"/w/app": [
{ name: "public", url: "https://github.com/acme/app.git" },
{ name: "origin", url: "[email protected]:acme/app.git" },
],
};
useProject.setState({ project: { root: "/w" } as never });
localStorage.setItem("openidea.github.repository.v1:/w", "acme/app");
ghAvailability.mockReturnValue(ready("https://ghe.example.com/acme/app"));
ghApi.mockImplementation(answer);
await refreshConnection();
expect(useGhRepository.getState().connection?.coordinates).toMatchObject({ host: "ghe.example.com" });
});
it("recognises SSH remotes of a server whose web address has a port", async () => {
layout = {
"/w/app": [
{ name: "origin", url: "[email protected]:acme/app.git" },
{ name: "fork", url: "ssh://[email protected]/al/app.git" },
{ name: "mirror", url: "https://ghe.example.com:8443/acme/app-mirror.git" },
],
};
ghAvailability.mockReturnValue(ready("https://ghe.example.com:8443/acme/app"));
ghApi.mockImplementation(answer);
await refreshConnection();
expect(remotesOf()).toEqual(["origin=ghe.example.com:8443/acme/app", "fork=ghe.example.com:8443/al/app"]);
expect(remotesOf()).toEqual([
"origin=ghe.example.com:8443/acme/app",
"fork=ghe.example.com:8443/al/app",
"mirror=ghe.example.com:8443/acme/app-mirror",
]);
});
});
+5 -1
Переглянути файл
@@ -233,10 +233,14 @@ export async function refreshConnection(): Promise<void> {
disconnect({ forget: false });
return;
}
// A choice saved without its host (before hosts were recorded): the origin remote's, when it is one of them.
const chosen = saved?.host
? saved
: (remotes.find((r) => r.remote === "origin" && sameRepository(r, saved)) ?? saved);
const target =
remotes.length === 1
? remotes[0]!
: (remotes.find((r) => sameRepository(r, current)) ?? remotes.find((r) => sameRepository(r, saved)) ?? null);
: (remotes.find((r) => sameRepository(r, current)) ?? remotes.find((r) => sameRepository(r, chosen)) ?? null);
// Only a choice among several repositories is remembered.
if (target) await connect(target, { remember: remotes.length > 1 });
else disconnect({ forget: false });