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 21, 13:30 UTC
fix(source-control): repository paths match however their names are percent-encoded (#36929)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Pavel Kroupa committed
Nov 14, 2026 at 22:55 UTC
b9a68e0f57c05e9eca0d7573dfbbd08e1cd6af52
8 files changed
+88
-16
apps/server/src/project/RepositoryIdentityResolver.ts
+4
-3
@@ -1,7 +1,7 @@
1
import type { RepositoryIdentity, SourceControlProviderError } from "@t3tools/contracts";
2
import { parseGitRemoteHost } from "@t3tools/source-control-core/shared/definition";
3
import { repositoryPathFromRemoteUrl } from "@t3tools/source-control-core/server/SourceControlProvider";
4
-import { normalizeGitRemoteUrl } from "@t3tools/shared/git";
4
+import { canonicalRepositoryPath, normalizeGitRemoteUrl } from "@t3tools/shared/git";
5
import * as Cache from "effect/Cache";
6
import * as Context from "effect/Context";
7
import * as Data from "effect/Data";
@@ -126,8 +126,9 @@ function repositoryPathOf(canonicalKey: string, remoteUrl: string): string {
126
if (displayPath === null) return canonicalPath;
127
// A host that names repositories literally keeps the `.git` the display path drops.
128
return (
129
- [displayPath, `${displayPath}.git`].find((path) => path.toLowerCase() === canonicalPath) ??
130
- canonicalPath
129
+ [displayPath, `${displayPath}.git`].find(
130
+ (path) => canonicalRepositoryPath(path) === canonicalRepositoryPath(canonicalPath),
131
+ ) ?? canonicalPath
132
);
133
}
134
packages/shared/src/git.test.ts
+3
@@ -33,6 +33,9 @@ describe("normalizeGitRemoteUrl", () => {
33
expect(normalizeGitRemoteUrl("https://github.com/T3Tools/T3Code.git#section")).toBe(
34
"github.com/t3tools/t3code",
35
);
36
+ expect(normalizeGitRemoteUrl("https://code.example.test/team/%C3%84pp.git")).toBe(
37
+ normalizeGitRemoteUrl("git@code.example.test:team/Äpp.git"),
38
+ );
39
expect(normalizeGitRemoteUrl("ssh://git@code.example.test/owner/repo.git.git")).toBe(
40
normalizeGitRemoteUrl("git@code.example.test:owner/repo.git.git"),
41
);
packages/shared/src/git.ts
+21
-3
@@ -124,6 +124,23 @@ export function isTemporaryWorktreeBranch(refName: string): boolean {
124
125
const stripGitSuffix = (path: string) => path.replace(/\.git$/i, "");
126
127
+function canonicalPathSegment(segment: string): string {
128
+ try {
129
+ // Lowercase before encoding: lowercasing the escape `%C3%84` never reaches the `Ä` it names.
130
+ return encodeURIComponent(decodeURIComponent(segment).toLowerCase()).toLowerCase();
131
+ } catch {
132
+ return segment.toLowerCase();
133
+ }
134
+}
135
+
136
+/**
137
+ * A repository path in one lower-case spelling. Remotes, browsers and agents escape a name
138
+ * differently (`a%20(b)`, `a%20%28b%29`, `a (b)`), and keys built from them are compared as text.
139
+ */
140
+export function canonicalRepositoryPath(path: string): string {
141
+ return path.split("/").map(canonicalPathSegment).join("/");
142
+}
143
+
144
function lowerCaseRemote(value: string, dropSuffix = stripGitSuffix): string {
145
return dropSuffix(value.trim().replace(/\/+$/g, "")).toLowerCase();
146
}
@@ -148,7 +165,7 @@ export function parseGitRemoteRepository(
165
.split("/")
166
.filter((segment) => segment.length > 0);
167
if (url.hostname && repositorySegments.length > 1) {
151
- return { host: url.hostname, path: repositorySegments.join("/") };
168
+ return { host: url.hostname, path: canonicalRepositoryPath(repositorySegments.join("/")) };
169
}
170
} catch {
171
return null;
@@ -164,10 +181,11 @@ export function parseGitRemoteRepository(
181
const scpHost = scpStyleHostAndPath?.[1];
182
const scpPath = scpStyleHostAndPath?.[2];
183
if (!scpHost || !scpPath) return null;
167
- if (!scpHost.startsWith("[")) return { host: scpHost, path: scpPath };
184
+ const path = canonicalRepositoryPath(scpPath);
185
+ if (!scpHost.startsWith("[")) return { host: scpHost, path };
186
try {
187
// Spell an IPv6 host as the URL branch does, so `[::1]:a/b` and `ssh://[::1]/a/b` share a key.
170
- return { host: new URL(`ssh://${scpHost}`).hostname, path: scpPath };
188
+ return { host: new URL(`ssh://${scpHost}`).hostname, path };
189
} catch {
190
return null;
191
}
packages/source-control-azure-devops/src/shared/definition.test.ts
+33
@@ -157,6 +157,39 @@ describe("Azure DevOps repository keys", () => {
157
).toBe(false);
158
});
159
160
+ it("matches a repository however its name is percent-encoded", () => {
161
+ const remoteUrl = "https://example@dev.azure.com/example/Sample%20(Beta)/_git/Sample%20(Beta)";
162
+ const canonicalKey = registry.repositoryKeyFromRemote(remoteUrl);
163
+ const identity: ChangeRequestProjectIdentity = {
164
+ canonicalKey,
165
+ locator: { source: "git-remote", remoteName: "origin", remoteUrl },
166
+ };
167
+ for (const url of [
168
+ "https://dev.azure.com/example/Sample%20%28Beta%29/_git/Sample%20%28Beta%29/pullrequest/7",
169
+ "https://dev.azure.com/example/Sample (Beta)/_git/Sample (Beta)/pullrequest/7",
170
+ ]) {
171
+ const link = parse(url)!;
172
+ expect(link.repository, url).toBe("example/sample%20(beta)/_git/sample%20(beta)");
173
+ expect(definition.isChangeRequestInRepository(identity, link), url).toBe(true);
174
+ expect(
175
+ definition.isChangeRequestInRepository(
176
+ {
177
+ ...identity,
178
+ canonicalKey: "dev.azure.com/example/sample%20%28beta%29/_git/sample%20%28beta%29",
179
+ },
180
+ link,
181
+ ),
182
+ url,
183
+ ).toBe(true);
184
+ }
185
+ // Links stored before keys had one spelling still resolve to their project.
186
+ expect(
187
+ registry.canonicalRepositoryKey(
188
+ "dev.azure.com/example/sample%20%28beta%29/_git/sample%20%28beta%29",
189
+ ),
190
+ ).toBe(canonicalKey);
191
+ });
192
+
193
it("still drops .git from other hosts' repository keys", () => {
194
expect(registry.repositoryKeyFromRemote("git@github.com:acme/tool.git")).toBe(
195
"github.com/acme/tool",
packages/source-control-azure-devops/src/shared/definition.ts
+3
-2
@@ -1,4 +1,5 @@
1
import { SourceControlProviderKind } from "@t3tools/contracts";
2
+import { canonicalRepositoryPath } from "@t3tools/shared/git";
3
import {
4
buildCommitUrl,
5
changeRequestUrlBelow,
@@ -156,8 +157,8 @@ export const definition = defineSourceControl({
157
canonicalRepositoryKey,
158
isChangeRequestInRepository: (identity, link) => {
159
if (!isChangeRequestAuthorityOfProject(identity, link)) return false;
159
- const projectKey = identity.canonicalKey.toLowerCase();
160
- const linkKey = `${link.host}/${link.repository}`.toLowerCase();
160
+ const projectKey = canonicalRepositoryPath(identity.canonicalKey);
161
+ const linkKey = canonicalRepositoryPath(`${link.host}/${link.repository}`);
162
return (
163
(canonicalRepositoryKey(projectKey) ?? projectKey) ===
164
(canonicalRepositoryKey(linkKey) ?? linkKey)
packages/source-control-core/src/shared/definition.ts
+18
-6
@@ -9,7 +9,11 @@ import {
9
TrimmedNonEmptyString,
10
TrimmedString,
11
} from "@t3tools/contracts";
12
-import { normalizeGitRemoteUrl, parseGitRemoteRepository } from "@t3tools/shared/git";
12
+import {
13
+ canonicalRepositoryPath,
14
+ normalizeGitRemoteUrl,
15
+ parseGitRemoteRepository,
16
+} from "@t3tools/shared/git";
17
import { userlessScpRemoteHost } from "@t3tools/shared/sourceControl";
18
import * as Effect from "effect/Effect";
19
import * as Schema from "effect/Schema";
@@ -379,7 +383,7 @@ export function parseCommitPath(url: URL, route: RegExp): CommitLink | null {
383
return repository && sha && FULL_COMMIT_SHA.test(sha)
384
? {
385
host: url.hostname.toLowerCase(),
382
- repository: repository.toLowerCase(),
386
+ repository: canonicalRepositoryPath(repository),
387
sha: sha.toLowerCase(),
388
...(url.port ? { authority: url.host.toLowerCase() } : {}),
389
}
@@ -417,7 +421,7 @@ export function parseChangeRequestPath(url: URL, route: RegExp): ParsedChangeReq
421
return repository && Number.isSafeInteger(number) && number > 0
422
? {
423
host: url.hostname.toLowerCase(),
420
- repository: repository.toLowerCase(),
424
+ repository: canonicalRepositoryPath(repository),
425
number,
426
repositoryUrl: `${url.origin}/${repository}`,
427
}
@@ -513,7 +517,7 @@ export function isChangeRequestInProjectRepository(
517
const repository = projectRepositoryPath(identity);
518
return (
519
repository !== null &&
516
- repository.toLowerCase() === link.repository.toLowerCase() &&
520
+ canonicalRepositoryPath(repository) === canonicalRepositoryPath(link.repository) &&
521
isChangeRequestOnProjectHost(projectHost, identity, link)
522
);
523
}
@@ -704,7 +708,15 @@ export function makeSourceControlDefinitionRegistry(
708
}
709
const claimOrder = inOrder(definitions, options?.claimChangeRequestUrlsFirst);
710
const recognitionOrder = inOrder(definitions, options?.recognizeRemotesIn);
707
- const repositoryKeyOwner = (key: string) => {
711
+ // Keys persisted before paths had one spelling still compare equal.
712
+ const canonicalKeyPath = (key: string) => {
713
+ const slash = key.indexOf("/");
714
+ return slash < 0
715
+ ? key
716
+ : `${key.slice(0, slash)}/${canonicalRepositoryPath(key.slice(slash + 1))}`;
717
+ };
718
+ const repositoryKeyOwner = (written: string) => {
719
+ const key = canonicalKeyPath(written);
720
for (const definition of definitions) {
721
const canonical = definition.canonicalRepositoryKey?.(key);
722
if (canonical != null) return { definition, canonical };
@@ -811,7 +823,7 @@ export function makeSourceControlDefinitionRegistry(
823
}
824
return key;
825
},
814
- canonicalRepositoryKey: (key) => repositoryKeyOwner(key)?.canonical ?? key,
826
+ canonicalRepositoryKey: (key) => repositoryKeyOwner(key)?.canonical ?? canonicalKeyPath(key),
827
findByRepositoryKey: (key) => repositoryKeyOwner(key)?.definition,
828
repositorySelector: (identity) =>
829
identity?.provider === undefined
packages/source-control-core/src/shared/threadPullRequests.ts
+3
-1
@@ -4,6 +4,7 @@ import type {
4
ThreadPullRequestKey,
5
ThreadPullRequestLink,
6
} from "@t3tools/contracts";
7
+import { canonicalRepositoryPath } from "@t3tools/shared/git";
8
import { visibleThreadPullRequests } from "@t3tools/shared/threadPullRequests";
9
10
import type { SourceControlDefinitionRegistry } from "./definition.ts";
@@ -73,7 +74,8 @@ export function makeThreadPullRequests(
74
const parsed = key.url === undefined ? null : parse(key.url);
75
const authority =
76
key.authority ??
76
- (parsed?.repository === key.repository.trim().toLowerCase() && parsed.number === key.number
77
+ (parsed?.repository === canonicalRepositoryPath(key.repository.trim()) &&
78
+ parsed.number === key.number
79
? parsed.authority
80
: undefined);
81
const canonical = registry.canonicalRepositoryKey(
packages/source-control-forgejo/src/shared/definition.ts
+3
-1
@@ -1,4 +1,5 @@
1
import { SourceControlProviderKind } from "@t3tools/contracts";
2
+import { canonicalRepositoryPath } from "@t3tools/shared/git";
3
import {
4
buildCommitUrl,
5
changeRequestUrlBelow,
@@ -130,7 +131,8 @@ export const definition = defineSourceControl({
131
return isChangeRequestInProjectRepository(changeRequestHost(identity), identity, link);
132
return (
133
web.host.toLowerCase() === (link.authority ?? link.host).toLowerCase() &&
133
- web.pathname.replace(/^\/+|\/+$/g, "").toLowerCase() === link.repository.toLowerCase()
134
+ canonicalRepositoryPath(web.pathname.replace(/^\/+|\/+$/g, "")) ===
135
+ canonicalRepositoryPath(link.repository)
136
);
137
},
138
// A server mounted below a path serves only repositories under that mount.