The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 05:45 UTC
fix(source-control): remotes like github.com:owner/repo reach their host (#29457)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
MarcoDotIO committed
Nov 3, 2026 at 18:17 UTC
2b4d6a3141fc4acf9c9ea4d67107fb46681ebdd4
12 files changed
+109
-9
apps/server/src/project/RepositoryIdentityResolver.test.ts
+19
@@ -51,6 +51,25 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
51
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
52
);
53
54
+ it.effect("identifies the host of an SSH remote that leaves its user to ssh config", () =>
55
+ Effect.gen(function* () {
56
+ const fileSystem = yield* FileSystem.FileSystem;
57
+ const cwd = yield* fileSystem.makeTempDirectoryScoped({
58
+ prefix: "t3-repository-identity-userless-remote-test-",
59
+ });
60
+
61
+ yield* git(cwd, ["init"]);
62
+ yield* git(cwd, ["remote", "add", "origin", "github.com:T3Tools/t3code.git"]);
63
+
64
+ const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
65
+ const identity = yield* resolver.resolve(cwd);
66
+
67
+ expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
68
+ expect(identity?.provider).toBe("github");
69
+ expect(identity?.displayName).toBe("T3Tools/t3code");
70
+ }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
71
+ );
72
+
73
it.effect("resolves the fetch remote of a partial clone", () =>
74
Effect.gen(function* () {
75
const fileSystem = yield* FileSystem.FileSystem;
apps/server/src/sourceControl/SourceControlProviderRegistry.test.ts
+18
@@ -199,6 +199,24 @@ it.effect("leaves a remote no integration claims unknown, with its server's addr
199
}),
200
);
201
202
+it.effect.each([
203
+ ["github.com:team/project.git", "github"],
204
+ ["gitlab.com:team/project.git", "gitlab"],
205
+ ["bitbucket.org:team/project.git", "bitbucket"],
206
+ ["code.example.test:team/project.git", "unknown"],
207
+] as const)(
208
+ "reads the host of an SSH remote that leaves its user to ssh config: %s",
209
+ ([url, expected]) =>
210
+ Effect.gen(function* () {
211
+ const registry = yield* makeRegistry({ remotes: [{ name: "origin", url }] });
212
+
213
+ const handle = yield* registry.resolveHandle({ cwd: "/repo" });
214
+
215
+ assert.strictEqual(handle.provider.kind, kind(expected));
216
+ assert.strictEqual(handle.context?.remoteUrl, url);
217
+ }),
218
+);
219
+
220
it.effect("refines the caller-selected remote instead of choosing another configured remote", () =>
221
Effect.gen(function* () {
222
const registry = yield* makeRegistry({
apps/server/src/sourceControl/sourceControlDefinitions.test.ts
+12
@@ -10,3 +10,15 @@ it("runs a driver for every host the server and clients read, in their order", (
10
sourceControlDefinitions.definitions,
11
);
12
});
13
+
14
+it.each([
15
+ "C:/repos/project",
16
+ "C:\\repos\\project",
17
+ "/srv/git/repo.git",
18
+ "./team:group/repo",
19
+ "file:///srv/git/repo.git",
20
+ "hg::team/repo",
21
+ "codecommit::us-east-1://repo",
22
+])("finds no host in %s, which git does not read as SSH", (remoteUrl) => {
23
+ expect(sourceControlDefinitions.recognizeRemote(remoteUrl)).toBeNull();
24
+});
packages/shared/src/sourceControl.test.ts
new
+25
@@ -0,0 +1,25 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+
3
+import { isSshRemoteUrl } from "./sourceControl.ts";
4
+
5
+describe("isSshRemoteUrl", () => {
6
+ it.each([
7
+ "git@github.com:owner/repo.git",
8
+ "ssh://git@github.com/owner/repo.git",
9
+ "github.com:owner/repo.git",
10
+ "github-work:owner/repo.git",
11
+ ])("reads %s as SSH", (remoteUrl) => {
12
+ expect(isSshRemoteUrl(remoteUrl)).toBe(true);
13
+ });
14
+
15
+ it.each([
16
+ "https://github.com/owner/repo.git",
17
+ "C:/repos/repo",
18
+ "/srv/git/repo.git",
19
+ "./team:group/repo",
20
+ "file:///srv/git/repo.git",
21
+ "hg::owner/repo",
22
+ ])("does not read %s as SSH", (remoteUrl) => {
23
+ expect(isSshRemoteUrl(remoteUrl)).toBe(false);
24
+ });
25
+});
packages/shared/src/sourceControl.ts
+13
-1
@@ -1,6 +1,18 @@
1
const SCP_SSH_REMOTE_PATTERN = /^[a-zA-Z0-9._-]+@([^:/]+):/;
2
+// Git reads `host:path` as SSH too, leaving the user to ssh config. A single letter is a Windows
3
+// drive and `::` names a remote helper.
4
+const USERLESS_SCP_SSH_REMOTE_PATTERN = /^([^@:/\\\s]{2,}):(?!:)\/?[^/\s]+(?:\/[^/\s]+)+\/?$/u;
5
+
6
+/** Null unless the remote is `host:path`, with no user. */
7
+export function userlessScpRemoteHost(remoteUrl: string): string | null {
8
+ return USERLESS_SCP_SSH_REMOTE_PATTERN.exec(remoteUrl.trim())?.[1] ?? null;
9
+}
10
11
export function isSshRemoteUrl(remoteUrl: string): boolean {
12
const trimmed = remoteUrl.trim();
5
- return SCP_SSH_REMOTE_PATTERN.test(trimmed) || trimmed.toLowerCase().startsWith("ssh://");
13
+ return (
14
+ SCP_SSH_REMOTE_PATTERN.test(trimmed) ||
15
+ trimmed.toLowerCase().startsWith("ssh://") ||
16
+ userlessScpRemoteHost(trimmed) !== null
17
+ );
18
}
packages/source-control-core/src/server/SourceControlProvider.test.ts
+14
-1
@@ -1,6 +1,9 @@
1
import { assert, it } from "@effect/vitest";
2
3
-import { transportSafeSourceControlErrorValue } from "./SourceControlProvider.ts";
3
+import {
4
+ repositoryPathFromRemoteUrl,
5
+ transportSafeSourceControlErrorValue,
6
+} from "./SourceControlProvider.ts";
7
8
it("removes URL credentials, query parameters, and fragments from error transport values", () => {
9
assert.strictEqual(
@@ -10,3 +13,13 @@ it("removes URL credentials, query parameters, and fragments from error transpor
13
"https://example.test/org/repo/pull/42",
14
);
15
});
16
+
17
+it.each([
18
+ ["git@github.com:T3Tools/t3code.git", "T3Tools/t3code"],
19
+ ["github.com:T3Tools/t3code.git", "T3Tools/t3code"],
20
+ ["gitlab.com:T3Tools/platform/t3code", "T3Tools/platform/t3code"],
21
+ ["https://github.com/T3Tools/t3code.git", "T3Tools/t3code"],
22
+ ["C:/repos/t3code", null],
23
+])("reads the repository path of %s", (remoteUrl, expected) => {
24
+ assert.strictEqual(repositoryPathFromRemoteUrl(remoteUrl), expected);
25
+});
packages/source-control-core/src/server/SourceControlProvider.ts
+1
-1
@@ -106,7 +106,7 @@ export function repositoryPathFromRemoteUrl(url: string | null): string | null {
106
}
107
108
const match =
109
- /^(?:[^@/\s]+@[^:/\s]+:|(?:ssh|https?|git):\/\/[^/]+\/)((?:[^/\s]+\/)+[^/\s]+?)(?:\.git)?\/?$/iu.exec(
109
+ /^(?:[^@/\s]+@[^:/\s]+:|[^@:/\\\s]{2,}:(?!:)|(?:ssh|https?|git):\/\/[^/]+\/)((?:[^/\s]+\/)+[^/\s]+?)(?:\.git)?\/?$/iu.exec(
110
trimmed,
111
);
112
const path = match?.[1]?.trim() ?? "";
packages/source-control-core/src/shared/definition.ts
+2
-1
@@ -10,6 +10,7 @@ import {
10
TrimmedString,
11
} from "@t3tools/contracts";
12
import { normalizeGitRemoteUrl, parseGitRemoteRepository } from "@t3tools/shared/git";
13
+import { userlessScpRemoteHost } from "@t3tools/shared/sourceControl";
14
import * as Effect from "effect/Effect";
15
import * as Schema from "effect/Schema";
16
import * as SchemaTransformation from "effect/SchemaTransformation";
@@ -498,7 +499,7 @@ export function parseGitRemoteHost(remoteUrl: string): GitRemoteHost | null {
499
const trimmed = remoteUrl.trim();
500
if (trimmed.length === 0) return null;
501
let host: string;
501
- const scpHost = SCP_REMOTE.exec(trimmed)?.[1];
502
+ const scpHost = SCP_REMOTE.exec(trimmed)?.[1] ?? userlessScpRemoteHost(trimmed);
503
if (scpHost) {
504
host = scpHost.toLowerCase();
505
} else {
packages/source-control-gitcafe/src/server/GitCafeSourceControlProvider.ts
+2
-1
@@ -20,6 +20,7 @@ import {
20
import { randomUuidV4 } from "@t3tools/provider-core/server/randomUuid";
21
import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
22
import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
23
+import { isSshRemoteUrl } from "@t3tools/shared/sourceControl";
24
import { parsePullRequestUrl } from "../shared/definition.ts";
25
26
import * as GitCafeApi from "./GitCafeApi.ts";
@@ -165,7 +166,7 @@ const cloneUrls = (target: Target) => ({
166
});
167
168
const isSshRemote = (remoteUrl: string | undefined) =>
168
- remoteUrl !== undefined && (/^ssh:\/\//iu.test(remoteUrl) || /^[^/:]+@[^/:]+:/u.test(remoteUrl));
169
+ remoteUrl !== undefined && isSshRemoteUrl(remoteUrl);
170
171
export const make = Effect.gen(function* () {
172
const api = yield* GitCafeApi.GitCafeApi;
packages/source-control-gitcafe/src/server/gitCafeHosts.test.ts
+1
@@ -16,6 +16,7 @@ describe("gitCafeHosts", () => {
16
["https://staging.git.cafe/team/project.git/", "staging.git.cafe"],
17
["ssh@git.cafe:team/project.git", "git.cafe"],
18
["ssh://git@git.cafe/team/project.git", "git.cafe"],
19
+ ["git.cafe:team/project.git", "git.cafe"],
20
])("reads the host and repository of %s", (url, host) => {
21
assert.deepStrictEqual(GitCafeHosts.parseGitCafeRemote(url), {
22
host,
packages/source-control-gitcafe/src/server/gitCafeHosts.ts
+1
-1
@@ -14,7 +14,7 @@ const REPOSITORY = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u;
14
const REMOTE_PATTERNS = [
15
/^https?:\/\/(?:[^@/]+@)?([^/:]+)(?::\d+)?\/(.+)$/iu,
16
/^ssh:\/\/[^@/]+@([^/:]+)(?::\d+)?\/(.+)$/iu,
17
- /^[^@/:]+@([^/:]+):(.+)$/u,
17
+ /^(?:[^@/:]+@)?([^/:]+):(.+)$/u,
18
];
19
20
export function gitCafeRepositoryPath(path: string): string | null {
packages/source-control-gitlab/src/server/GitLabSourceControlProvider.ts
+1
-3
@@ -110,9 +110,7 @@ function refineUnknownGitLabRemote(input: SourceControlUnknownRemoteRefinementIn
110
111
/** The caller refines only an identity no host recognised, so its remote is on an unknown host. */
112
function unknownRemoteProvider(remoteUrl: string) {
113
- // Remote host parsing does not recognize userless SCP remotes.
114
- const scpHost = /^([^@:/\\\s]{2,}):\/?[^/\s]+(?:\/[^/\s]+)+$/u.exec(remoteUrl.trim())?.[1];
115
- const remote = parseGitRemoteHost(scpHost ? `ssh://${scpHost}` : remoteUrl);
113
+ const remote = parseGitRemoteHost(remoteUrl);
114
return remote === null ? null : unknownHostProvider(remote);
115
}
116