mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
fix(projects): normalize default remote ports
This commit is contained in:
@@ -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");
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user