fix(projects): retain absolute scp users

This commit is contained in:
Mohamed Boudra
2026-07-29 10:45:23 +00:00
parent 1f467fa43e
commit 7e43d90aa5
2 changed files with 19 additions and 6 deletions

View File

@@ -189,6 +189,21 @@ describe("deriveProjectKey", () => {
);
});
test("distinguishes SSH users for absolute SCP paths", () => {
const rootPath = path.resolve("repo");
const derive = (remoteUrl: string) =>
deriveProjectKey({
rootPath,
remoteUrl,
worktreeRoot: rootPath,
mainRepoRoot: null,
});
expect(derive("alice@git.example.com:/srv/repo.git")).not.toBe(
derive("bob@git.example.com:/srv/repo.git"),
);
});
test("distinguishes SSH users for generic URL remotes", () => {
const rootPath = path.resolve("repo");
const derive = (remoteUrl: string) =>

View File

@@ -70,9 +70,7 @@ function deriveRemoteProjectKey(remoteUrl: string | null): string | null {
remote.stripDotGitSuffix,
);
if (!cleanedPath) return null;
const userPrefix = remote.relativePathUser
? `${encodeURIComponent(remote.relativePathUser)}@`
: "";
const userPrefix = remote.user ? `${encodeURIComponent(remote.user)}@` : "";
const normalizedHost = remote.host.toLowerCase();
const normalizedPath = normalizedHost === "github.com" ? cleanedPath.toLowerCase() : cleanedPath;
const transportPrefix = remote.transport ? `${remote.transport}//` : "";
@@ -83,7 +81,7 @@ interface RemoteLocation {
host: string;
path: string;
transport: string | null;
relativePathUser: string | null;
user: string | null;
preserveLeadingSlash: boolean;
decodePercentEncoding: boolean;
stripDotGitSuffix: boolean;
@@ -107,7 +105,7 @@ function parseScpRemote(remoteUrl: string): RemoteLocation | null {
host: normalizedHost,
path: remotePath,
transport: null,
relativePathUser: user && user !== "git" && !preserveLeadingSlash ? user : null,
user: user && user !== "git" ? user : null,
preserveLeadingSlash,
decodePercentEncoding: false,
stripDotGitSuffix: CLOUD_FORGE_HOSTS.has(host.toLowerCase()),
@@ -130,7 +128,7 @@ function parseUrlRemote(remoteUrl: string): RemoteLocation | null {
host,
path: remotePath,
transport: forgeHost || isSsh ? null : parsed.protocol.toLowerCase(),
relativePathUser:
user:
isSsh && !forgeHost && parsed.username && parsed.username !== "git"
? decodeUrlComponent(parsed.username)
: null,