fix(projects): normalize default remote ports

This commit is contained in:
Mohamed Boudra
2026-07-29 00:02:16 +00:00
parent 5928dc08d9
commit e849518c76
2 changed files with 23 additions and 1 deletions

View File

@@ -18,6 +18,19 @@ describe("deriveProjectGroupKey", () => {
).toBe("remote:git.example.com:8443/acme/app");
});
test("normalizes the default SSH port", () => {
const rootPath = path.resolve("repo");
expect(
deriveProjectGroupKey({
rootPath,
remoteUrl: "ssh://git@github.com:22/getpaseo/paseo.git",
worktreeRoot: rootPath,
mainRepoRoot: null,
}),
).toBe("remote:github.com/getpaseo/paseo");
});
test("accepts a root-level remote repository path", () => {
const rootPath = path.resolve("repo");

View File

@@ -47,7 +47,7 @@ function deriveRemoteProjectGroupKey(remoteUrl: string | null): string | null {
} else if (trimmed.includes("://")) {
try {
const parsed = new URL(trimmed);
host = parsed.host || null;
host = deriveRemoteHost(parsed);
remotePath = parsed.pathname ? parsed.pathname.replace(/^\/+/, "") : null;
} catch {
return null;
@@ -60,3 +60,12 @@ function deriveRemoteProjectGroupKey(remoteUrl: string | null): string | null {
if (!cleanedPath) return null;
return `remote:${host.toLowerCase()}/${cleanedPath}`;
}
function deriveRemoteHost(remoteUrl: URL): string | null {
const defaultPorts: Partial<Record<string, string>> = {
"git:": "9418",
"ssh:": "22",
};
if (remoteUrl.port === defaultPorts[remoteUrl.protocol]) return remoteUrl.hostname || null;
return remoteUrl.host || null;
}