Skip to content

Commit 1017139

Browse files
fix(server): gh OWNER/REPO marks match remotes on the same HTTP port
normalizeGitRemoteUrl drops ports, so a parent on another HTTPS port of the same hostname could be picked. Compare hosts with parseGitRemoteHost, which keeps HTTP ports and ignores SSH transport ports. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ce65b22 commit 1017139

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎apps/server/src/project/RepositoryIdentityResolver.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,15 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
372372
yield* git(cwd, ["config", "remote.fork.gh-resolved", "base"]);
373373
yield* git(cwd, ["config", "remote.main.gh-resolved", "base"]);
374374
expect((yield* resolveFresh())?.locator.remoteName).toBe("upstream");
375+
376+
// The same path on another HTTPS port is a different server.
377+
yield* git(cwd, ["config", "--unset", "remote.fork.gh-resolved"]);
378+
yield* git(cwd, ["config", "--unset", "remote.main.gh-resolved"]);
379+
yield* git(cwd, ["remote", "add", "backup", "https://ghe.example.com:9443/acme/web.git"]);
380+
yield* git(cwd, ["remote", "add", "ghe-fork", "https://ghe.example.com:8443/me/web.git"]);
381+
yield* git(cwd, ["remote", "add", "ghe-parent", "https://ghe.example.com:8443/acme/web.git"]);
382+
yield* git(cwd, ["config", "remote.ghe-fork.gh-resolved", "acme/web"]);
383+
expect((yield* resolveFresh())?.locator.remoteName).toBe("ghe-parent");
375384
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
376385
);
377386

‎apps/server/src/project/RepositoryIdentityResolver.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { RepositoryIdentity, SourceControlProviderError } from "@t3tools/contracts";
2+
import { parseGitRemoteHost } from "@t3tools/source-control-core/shared/definition";
23
import { repositoryPathFromRemoteUrl } from "@t3tools/source-control-core/server/SourceControlProvider";
34
import { normalizeGitRemoteUrl } from "@t3tools/shared/git";
45
import * as Cache from "effect/Cache";
@@ -88,10 +89,15 @@ function pickMarkedRemote(
8889
const [mark, ...others] = marks;
8990
if (!mark || others.length > 0) return null;
9091
if (mark.value === "base") return { remoteName: mark.remoteName, remoteUrl: mark.remoteUrl };
91-
const host = normalizeGitRemoteUrl(mark.remoteUrl).split("/")[0];
92-
const markedKey = `${host}/${mark.value.toLowerCase()}`;
92+
// Compare hosts with HTTP ports kept: one hostname can serve separate forges on two ports.
93+
const host = parseGitRemoteHost(mark.remoteUrl)?.host;
94+
const markedPath = mark.value.toLowerCase();
9395
const [remoteName, remoteUrl] =
94-
[...remotes.entries()].find(([, url]) => normalizeGitRemoteUrl(url) === markedKey) ?? [];
96+
[...remotes.entries()].find(
97+
([, url]) =>
98+
parseGitRemoteHost(url)?.host === host &&
99+
normalizeGitRemoteUrl(url).split("/").slice(1).join("/") === markedPath,
100+
) ?? [];
95101
return remoteName && remoteUrl ? { remoteName, remoteUrl } : null;
96102
}
97103

0 commit comments

Comments
 (0)