Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix: detect SSH remotes with non-git user prefixes (e.g. gitlab@) (#3649)

JackatDJL7ce4194707e2
diff --git a/apps/server/src/git/GitManager.ts b/apps/server/src/git/GitManager.ts
index bed5a8839..1c9684b0d 100644
--- a/apps/server/src/git/GitManager.ts
+++ b/apps/server/src/git/GitManager.ts
@@ -42,6 +42,7 @@ import {
} from "@t3tools/shared/git";
import {
getChangeRequestTerminologyForKind,
+ isSshRemoteUrl,
type ChangeRequestTerminology,
} from "@t3tools/shared/sourceControl";
@@ -574,8 +575,7 @@ function toResolvedPullRequest(pr: {
function shouldPreferSshRemote(url: string | null): boolean {
if (!url) return false;
- const trimmed = url.trim();
- return trimmed.startsWith("git@") || trimmed.startsWith("ssh://");
+ return isSshRemoteUrl(url);
}
function toPullRequestHeadRemoteInfo(pr: {
diff --git a/apps/server/src/sourceControl/BitbucketApi.ts b/apps/server/src/sourceControl/BitbucketApi.ts
index aad28ee8c..4a825be88 100644
--- a/apps/server/src/sourceControl/BitbucketApi.ts
+++ b/apps/server/src/sourceControl/BitbucketApi.ts
@@ -14,7 +14,10 @@ import {
} from "@t3tools/contracts";
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
import { sanitizeBranchFragment } from "@t3tools/shared/git";
-import { detectSourceControlProviderFromRemoteUrl } from "@t3tools/shared/sourceControl";
+import {
+ detectSourceControlProviderFromRemoteUrl,
+ isSshRemoteUrl,
+} from "@t3tools/shared/sourceControl";
import {
BitbucketPullRequestListSchema,
@@ -448,9 +451,9 @@ function requireRepositoryLocator(
function parseBitbucketRemoteUrl(remoteUrl: string): BitbucketRepositoryLocator | null {
const trimmed = remoteUrl.trim();
- if (trimmed.startsWith("git@")) {
- const pathStart = trimmed.indexOf(":");
- return pathStart < 0 ? null : parseBitbucketRepositorySlug(trimmed.slice(pathStart + 1));
+ const scpMatch = /^[a-zA-Z0-9._-]+@[^:/]+:(.+)$/.exec(trimmed);
+ if (scpMatch?.[1]) {
+ return parseBitbucketRepositorySlug(scpMatch[1]);
}
try {
@@ -494,8 +497,8 @@ function defaultChangeRequestTargetBranch(input: {
}
function shouldPreferSshRemote(originRemoteUrl: string | null): boolean {
- const trimmed = originRemoteUrl?.trim() ?? "";
- return trimmed.startsWith("git@") || trimmed.startsWith("ssh://");
+ if (!originRemoteUrl) return false;
+ return isSshRemoteUrl(originRemoteUrl);
}
function selectCloneUrl(input: {
diff --git a/packages/shared/src/git.test.ts b/packages/shared/src/git.test.ts
index 96539f0aa..8dea20f0b 100644
--- a/packages/shared/src/git.test.ts
+++ b/packages/shared/src/git.test.ts
@@ -40,6 +40,15 @@ describe("normalizeGitRemoteUrl", () => {
"gitlab.company.com/team/project",
);
});
+
+ it("normalizes SCP-like remotes with non-git SSH users", () => {
+ expect(normalizeGitRemoteUrl("[email protected]:group/project.git")).toBe(
+ "gitlab.example.com/group/project",
+ );
+ expect(normalizeGitRemoteUrl("[email protected]:workspace/repo.git")).toBe(
+ "bitbucket.org/workspace/repo",
+ );
+ });
});
describe("parseGitHubRepositoryNameWithOwnerFromRemoteUrl", () => {
diff --git a/packages/shared/src/git.ts b/packages/shared/src/git.ts
index 71fe2e806..7c088970d 100644
--- a/packages/shared/src/git.ts
+++ b/packages/shared/src/git.ts
@@ -133,7 +133,9 @@ export function normalizeGitRemoteUrl(value: string): string {
}
}
- const scpStyleHostAndPath = /^git@([^:/\s]+)[:/]([^/\s]+(?:\/[^/\s]+)+)$/i.exec(normalized);
+ const scpStyleHostAndPath = /^[a-zA-Z0-9._-]+@([^:/\s]+):([^/\s]+(?:\/[^/\s]+)+)$/i.exec(
+ normalized,
+ );
if (scpStyleHostAndPath?.[1] && scpStyleHostAndPath[2]) {
return `${scpStyleHostAndPath[1]}/${scpStyleHostAndPath[2]}`;
}
diff --git a/packages/shared/src/sourceControl.test.ts b/packages/shared/src/sourceControl.test.ts
index 3842fa84b..86b1ba591 100644
--- a/packages/shared/src/sourceControl.test.ts
+++ b/packages/shared/src/sourceControl.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vite-plus/test";
import {
detectSourceControlProviderFromRemoteUrl,
getChangeRequestTerminologyForKind,
+ isSshRemoteUrl,
resolveChangeRequestPresentation,
} from "./sourceControl.ts";
@@ -120,4 +121,42 @@ describe("detectSourceControlProviderFromRemoteUrl", () => {
)?.kind,
).toBe("unknown");
});
+
+ it("detects SSH remotes with non-git SSH users (e.g. gitlab@, deploy@)", () => {
+ expect(
+ detectSourceControlProviderFromRemoteUrl("[email protected]:group/project.git")?.kind,
+ ).toBe("gitlab");
+ expect(
+ detectSourceControlProviderFromRemoteUrl("[email protected]:group/project.git")
+ ?.baseUrl,
+ ).toBe("https://gitlab.example.com");
+ expect(detectSourceControlProviderFromRemoteUrl("[email protected]:owner/repo.git")?.kind).toBe(
+ "github",
+ );
+ expect(
+ detectSourceControlProviderFromRemoteUrl("[email protected]:workspace/repo.git")?.kind,
+ ).toBe("bitbucket");
+ });
+});
+
+describe("isSshRemoteUrl", () => {
+ it("recognises SCP-like SSH URLs with any SSH user prefix", () => {
+ expect(isSshRemoteUrl("[email protected]:owner/repo.git")).toBe(true);
+ expect(isSshRemoteUrl("[email protected]:group/project.git")).toBe(true);
+ expect(isSshRemoteUrl("[email protected]:workspace/repo.git")).toBe(true);
+ });
+
+ it("recognises ssh:// URLs with any case", () => {
+ expect(isSshRemoteUrl("ssh://[email protected]/group/project.git")).toBe(true);
+ expect(isSshRemoteUrl("ssh://[email protected]:22/group/project.git")).toBe(true);
+ expect(isSshRemoteUrl("SSH://[email protected]/group/project.git")).toBe(true);
+ expect(isSshRemoteUrl("SsH://[email protected]/group/project.git")).toBe(true);
+ });
+
+ it("returns false for HTTPS, local paths, and SCP-like paths without a colon", () => {
+ expect(isSshRemoteUrl("https://gitlab.example.com/group/project.git")).toBe(false);
+ expect(isSshRemoteUrl("/home/user/repos/project")).toBe(false);
+ expect(isSshRemoteUrl("")).toBe(false);
+ expect(isSshRemoteUrl("[email protected]/project/repo")).toBe(false);
+ });
});
diff --git a/packages/shared/src/sourceControl.ts b/packages/shared/src/sourceControl.ts
index ad6fa890b..df88de595 100644
--- a/packages/shared/src/sourceControl.ts
+++ b/packages/shared/src/sourceControl.ts
@@ -133,19 +133,22 @@ export function getChangeRequestTerminologyForKind(
};
}
+const SCP_SSH_REMOTE_PATTERN = /^[a-zA-Z0-9._-]+@([^:/]+):/;
+
+export function isSshRemoteUrl(remoteUrl: string): boolean {
+ const trimmed = remoteUrl.trim();
+ return SCP_SSH_REMOTE_PATTERN.test(trimmed) || trimmed.toLowerCase().startsWith("ssh://");
+}
+
function parseRemoteHost(remoteUrl: string): string | null {
const trimmed = remoteUrl.trim();
if (trimmed.length === 0) {
return null;
}
- if (trimmed.startsWith("git@")) {
- const hostWithPath = trimmed.slice("git@".length);
- const separatorIndex = hostWithPath.search(/[:/]/);
- if (separatorIndex <= 0) {
- return null;
- }
- return hostWithPath.slice(0, separatorIndex).toLowerCase();
+ const scpMatch = SCP_SSH_REMOTE_PATTERN.exec(trimmed);
+ if (scpMatch?.[1]) {
+ return scpMatch[1].toLowerCase();
}
try {