@devries-cameron20 / t3code Mirror · read-only / commits / 4d5d5f89d4
Fork 0

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, 16:00 UTC

fix(source-control): preserve .git in Azure DevOps repository names (#36576)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 14, 2026 at 09:48 UTC 4d5d5f89d418c92a1478e15dace1e428f0fc13e8
6 files changed +91 -27
apps/server/src/project/RepositoryIdentityResolver.test.ts
+25
@@ -8,6 +8,7 @@ import * as Path from "effect/Path";
8 import { vi } from "vite-plus/test";
9
10 import * as ProcessRunner from "../processRunner.ts";
11 +import { sourceControlDefinitions } from "../sourceControl/sourceControlDefinitions.ts";
12 import * as RepositoryIdentityResolver from "./RepositoryIdentityResolver.ts";
13
14 const normalizePathSeparators = (value: string) => value.replaceAll("\\", "/");
@@ -71,6 +72,30 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
72 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
73 );
74
75 + it.effect("keeps a literal .git in an Azure DevOps repository name", () =>
76 + Effect.gen(function* () {
77 + const fileSystem = yield* FileSystem.FileSystem;
78 + const cwd = yield* fileSystem.makeTempDirectoryScoped({
79 + prefix: "t3-repository-identity-azure-git-suffix-test-",
80 + });
81 +
82 + yield* git(cwd, ["init"]);
83 + yield* git(cwd, [
84 + "remote",
85 + "add",
86 + "origin",
87 + "https://dev.azure.com/Acme/Platform/_git/Tool.git",
88 + ]);
89 +
90 + const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
91 + const identity = yield* resolver.resolve(cwd);
92 +
93 + expect(identity?.displayName).toBe("Acme/Platform/_git/Tool.git");
94 + expect(identity?.name).toBe("Tool.git");
95 + expect(sourceControlDefinitions.repositorySelector(identity)).toBe("Tool.git");
96 + }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
97 + );
98 +
99 it.effect("resolves the fetch remote of a partial clone", () =>
100 Effect.gen(function* () {
101 const fileSystem = yield* FileSystem.FileSystem;
apps/server/src/project/RepositoryIdentityResolver.ts
+6 -1
@@ -123,7 +123,12 @@ function pickPrimaryRemote(
123 function repositoryPathOf(canonicalKey: string, remoteUrl: string): string {
124 const canonicalPath = canonicalKey.split("/").slice(1).join("/");
125 const displayPath = repositoryPathFromRemoteUrl(remoteUrl);
126 - return displayPath?.toLowerCase() === canonicalPath ? displayPath : canonicalPath;
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
131 + );
132 }
133
134 function buildRepositoryOrigin(
packages/shared/src/git.ts
+12 -13
@@ -122,30 +122,29 @@ export function isTemporaryWorktreeBranch(refName: string): boolean {
122 return TEMP_WORKTREE_BRANCH_PATTERN.test(refName.trim().toLowerCase());
123 }
124
125 -function lowerCaseRemote(value: string): string {
126 - return value
127 - .trim()
128 - .replace(/\/+$/g, "")
129 - .replace(/\.git$/i, "")
130 - .toLowerCase();
125 +const stripGitSuffix = (path: string) => path.replace(/\.git$/i, "");
126 +
127 +function lowerCaseRemote(value: string, dropSuffix = stripGitSuffix): string {
128 + return dropSuffix(value.trim().replace(/\/+$/g, "")).toLowerCase();
129 }
130
131 /**
132 * The host and repository path a remote names, lower case and without a port, or null for a
135 - * remote that names no host, such as a local path.
133 + * remote that names no host, such as a local path. Most hosts serve `name.git` as `name`, so the
134 + * path drops that suffix unless `keepGitSuffix` asks for the name as written.
135 */
136 export function parseGitRemoteRepository(
137 value: string,
138 + options?: { readonly keepGitSuffix?: boolean },
139 ): { readonly host: string; readonly path: string } | null {
140 - const normalized = lowerCaseRemote(value);
140 + const dropSuffix = options?.keepGitSuffix ? (path: string) => path : stripGitSuffix;
141 + const normalized = lowerCaseRemote(value, dropSuffix);
142
143 if (/^(?:ssh|https?|git):\/\//i.test(normalized)) {
144 try {
144 - // Parse the raw remote: `.git` may sit before a query or fragment, so strip it from the path once.
145 + // Apply suffix policy to the path: `.git` may sit before a query or fragment.
146 const url = new URL(value.trim().toLowerCase());
146 - const repositorySegments = url.pathname
147 - .replace(/\/+$/, "")
148 - .replace(/\.git$/, "")
147 + const repositorySegments = dropSuffix(url.pathname.replace(/\/+$/, ""))
148 .split("/")
149 .filter((segment) => segment.length > 0);
150 if (url.hostname && repositorySegments.length > 1) {
@@ -176,7 +175,7 @@ export function parseGitRemoteRepository(
175
176 /**
177 * `host/path` for a remote that names a host, otherwise the remote itself, lower case. A host that
179 - * spells repositories differently over SSH has its source control registry's
178 + * spells repositories differently over SSH or treats `.git` literally has its source control registry's
179 * `repositoryKeyFromRemote` rewrite this, so persisted keys come from that, not from here.
180 */
181 export function normalizeGitRemoteUrl(value: string): string {
packages/source-control-azure-devops/src/shared/definition.test.ts
+26
@@ -137,6 +137,32 @@ describe("Azure DevOps repository keys", () => {
137 }
138 });
139
140 + it.each([
141 + "git@ssh.dev.azure.com:v3/acme/platform/tool.git",
142 + "https://dev.azure.com/acme/platform/_git/tool.git",
143 + ])("preserves a literal .git in an Azure repository name: %s", (remoteUrl) => {
144 + const canonicalKey = registry.repositoryKeyFromRemote(remoteUrl);
145 + expect(canonicalKey).toBe("dev.azure.com/acme/platform/_git/tool.git");
146 + const identity: ChangeRequestProjectIdentity = {
147 + canonicalKey,
148 + locator: { source: "git-remote", remoteName: "origin", remoteUrl },
149 + };
150 + const link = parse("https://dev.azure.com/acme/platform/_git/tool.git/pullrequest/7")!;
151 + expect(definition.isChangeRequestInRepository(identity, link)).toBe(true);
152 + expect(
153 + definition.isChangeRequestInRepository(identity, {
154 + ...link,
155 + repository: "acme/platform/_git/tool",
156 + }),
157 + ).toBe(false);
158 + });
159 +
160 + it("still drops .git from other hosts' repository keys", () => {
161 + expect(registry.repositoryKeyFromRemote("git@github.com:acme/tool.git")).toBe(
162 + "github.com/acme/tool",
163 + );
164 + });
165 +
166 it("keeps the organization in the host for the legacy visualstudio.com remotes", () => {
167 for (const remote of [
168 "T3Tools@vs-ssh.visualstudio.com:v3/T3Tools/Platform/T3Code",
packages/source-control-azure-devops/src/shared/definition.ts
+16 -7
@@ -17,6 +17,17 @@ const CHECKOUT_COMMAND = /^az\s+repos\s+pr\s+checkout\s+(.+)$/i;
17 const CHANGE_REQUEST_REFERENCE =
18 /^https:\/\/(?:dev\.azure\.com\/[^/\s]+\/[^/\s]+|[^/\s]+\.visualstudio\.com\/(?:DefaultCollection\/)?[^/\s]+)\/_git\/[^/\s]+\/pullrequest\/(\d+)(?:[/?#].*)?$/i;
19
20 +// `ssh.dev.azure.com` is the default SSH clone host (git@ssh.dev.azure.com:v3/org/project/repo),
21 +// so any `*.dev.azure.com` subdomain is Azure. Legacy hosts stay under `.visualstudio.com`,
22 +// including `vs-ssh.visualstudio.com`.
23 +function isAzureHostname(hostname: string): boolean {
24 + return (
25 + hostname === "dev.azure.com" ||
26 + hostname.endsWith(".dev.azure.com") ||
27 + hostname.endsWith(".visualstudio.com")
28 + );
29 +}
30 +
31 /**
32 * Azure alone addresses one repository under two names that share no part: `ssh.dev.azure.com` and
33 * `v3/{org}/{project}/{repo}` over SSH, against `dev.azure.com` and `{org}/{project}/_git/{repo}`
@@ -26,7 +37,10 @@ const CHANGE_REQUEST_REFERENCE =
37 function repositoryKeyFromRemote(key: string): string | null {
38 const match =
39 /^(ssh\.dev\.azure\.com|vs-ssh\.visualstudio\.com)\/v3\/([^/]+)\/([^/]+)\/([^/]+)$/u.exec(key);
29 - if (match === null) return null;
40 + if (match === null) {
41 + // Azure takes a name as written, so its keys keep the `.git` other hosts drop.
42 + return isAzureHostname(key.split("/", 1)[0]!) ? key : null;
43 + }
44 const [, host, organization, project, repository] = match;
45 return host === "ssh.dev.azure.com"
46 ? `dev.azure.com/${organization}/${project}/_git/${repository}`
@@ -125,13 +139,8 @@ export const definition = defineSourceControl({
139 },
140 isChangeRequestReference: (url) => CHANGE_REQUEST_REFERENCE.test(url),
141 checkoutChangeRequestHost: () => null,
128 - // `ssh.dev.azure.com` is the default SSH clone host (git@ssh.dev.azure.com:v3/org/project/repo),
129 - // so any `*.dev.azure.com` subdomain is Azure. Legacy hosts stay under `.visualstudio.com`,
130 - // including `vs-ssh.visualstudio.com`.
142 recognizeRemote: ({ host, hostname }) =>
132 - hostname === "dev.azure.com" ||
133 - hostname.endsWith(".dev.azure.com") ||
134 - hostname.endsWith(".visualstudio.com")
143 + isAzureHostname(hostname)
144 ? { kind: KIND, name: "Azure DevOps", baseUrl: `https://${host}` }
145 : null,
146 /**
packages/source-control-core/src/shared/definition.ts
+6 -6
@@ -338,10 +338,9 @@ export interface SourceControlDefinition {
338 */
339 readonly repositorySelector?: (identity: RepositorySelectorIdentity) => string | null;
340 /**
341 - * For a host that spells one repository differently over SSH and on the web: the web spelling
342 - * of the `host/path` key `normalizeGitRemoteUrl` made from a remote that names a host. Null when
343 - * the key is not this host's. Persisted repository keys are built with it, so its output must
344 - * not change.
341 + * The key of a remote's lower case `host/path`, `.git` suffix kept, for a host that spells it
342 + * apart from `normalizeGitRemoteUrl`: over SSH and the web, or with `.git` as part of the name.
343 + * Null when the key is not this host's. Persisted keys are built with it: output must not change.
344 */
345 readonly repositoryKeyFromRemote?: (key: string) => string | null;
346 /**
@@ -804,9 +803,10 @@ export function makeSourceControlDefinitionRegistry(
803 },
804 repositoryKeyFromRemote: (remoteUrl) => {
805 const key = normalizeGitRemoteUrl(remoteUrl);
807 - if (parseGitRemoteRepository(remoteUrl) === null) return key;
806 + const written = parseGitRemoteRepository(remoteUrl, { keepGitSuffix: true });
807 + if (written === null) return key;
808 for (const definition of definitions) {
809 - const spelled = definition.repositoryKeyFromRemote?.(key);
809 + const spelled = definition.repositoryKeyFromRemote?.(`${written.host}/${written.path}`);
810 if (spelled != null) return spelled;
811 }
812 return key;