@devries-cameron20 / t3code Mirror · read-only / commits / fad24fc863
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 22, 02:00 UTC

fix(azure-devops): default-branch lookup no longer fails for missing --repository (#29586)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Lakshmi Tanmay committed Nov 7, 2026 at 16:07 UTC fad24fc863ae4a4ae55649bd4868c1b103c3faf9
3 files changed +94 -3
packages/source-control-azure-devops/src/server/AzureDevOpsCli.ts
+11 -1
@@ -256,6 +256,7 @@ export class AzureDevOpsCli extends Context.Service<
256
257 readonly getDefaultBranch: (input: {
258 readonly cwd: string;
259 + readonly repository: string;
260 }) => Effect.Effect<string | null, AzureDevOpsCliError>;
261
262 readonly checkoutPullRequest: (input: {
@@ -552,9 +553,18 @@ export const make = Effect.gen(function* () {
553 }).pipe(Effect.asVoid);
554 }),
555 getDefaultBranch: Effect.fn("AzureDevOpsCli.getDefaultBranch")(function (input) {
556 + const repository = parseRepositorySpecifier(input.repository);
557 return executeJson({
558 cwd: input.cwd,
557 - args: ["repos", "show", "--detect", "true"],
559 + args: [
560 + "repos",
561 + "show",
562 + "--detect",
563 + "true",
564 + // Joined so a name starting with `-` stays the option's value.
565 + `--repository=${repository.name}`,
566 + ...(repository.project ? ["--project", repository.project] : []),
567 + ],
568 }).pipe(
569 Effect.map((result) => result.stdout.trim()),
570 Effect.flatMap((raw) =>
packages/source-control-azure-devops/src/server/AzureDevOpsSourceControlProvider.test.ts
+63 -1
@@ -1,5 +1,9 @@
1 +import * as NodeServices from "@effect/platform-node/NodeServices";
2 +import { SourceControlProviderKind } from "@t3tools/contracts";
3 +import type * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
4 +import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";
5 import { processOutput } from "@t3tools/source-control-testing/TestSourceControlHost";
2 -import { assert, it } from "@effect/vitest";
6 +import { assert, it, vi } from "@effect/vitest";
7 import * as Effect from "effect/Effect";
8 import * as Layer from "effect/Layer";
9 import * as Option from "effect/Option";
@@ -29,6 +33,64 @@ it("reads the signed-in Azure account and says when az is signed out", () => {
33 assert.strictEqual(parseAuth(processOutput("\n")).status, "unknown");
34 });
35
36 +it.effect("names the remote's repository when reading the default branch", () => {
37 + const run = vi.fn<SourceControlHost.SourceControlHost["Service"]["process"]["run"]>(() =>
38 + Effect.succeed(
39 + processOutput(
40 + JSON.stringify({
41 + name: "My Repo",
42 + webUrl: "https://dev.azure.com/acme/project/_git/My%20Repo",
43 + remoteUrl: "https://dev.azure.com/acme/project/_git/My%20Repo",
44 + sshUrl: "git@ssh.dev.azure.com:v3/acme/project/My%20Repo",
45 + defaultBranch: "refs/heads/master",
46 + }),
47 + ),
48 + ),
49 + );
50 + const support = Layer.mergeAll(
51 + TestSourceControlHost.layer({ process: { run } }),
52 + NodeServices.layer,
53 + );
54 + return Effect.gen(function* () {
55 + const provider = yield* AzureDevOpsSourceControlProvider.make;
56 + for (const [remoteUrl, repository] of [
57 + ["https://acme@dev.azure.com/acme/project/_git/My%20Repo", "My Repo"],
58 + ["https://dev.azure.com/acme/project/_git/My%20Repo?view=x#readme", "My Repo"],
59 + ["https://acme.visualstudio.com/DefaultCollection/project/_git/My%20Repo/", "My Repo"],
60 + ["git@ssh.dev.azure.com:v3/acme/project/My%20Repo", "My Repo"],
61 + ["ssh://git@ssh.dev.azure.com/v3/acme/project/My%20Repo", "My Repo"],
62 + ["https://dev.azure.com/acme/project/_git/service.git", "service.git"],
63 + ["https://dev.azure.com/acme/project/_git/-repo", "-repo"],
64 + ["https://dev.azure.com/acme/project/_git/%40.env", null],
65 + ] as const) {
66 + run.mockClear();
67 + const branch = yield* provider.getDefaultBranch({
68 + cwd: "/repo",
69 + context: {
70 + provider: {
71 + kind: SourceControlProviderKind.make("azure-devops"),
72 + name: "Azure DevOps",
73 + baseUrl: "https://dev.azure.com",
74 + },
75 + remoteName: "origin",
76 + remoteUrl,
77 + },
78 + });
79 + if (repository === null) {
80 + assert.strictEqual(branch, null, remoteUrl);
81 + assert.strictEqual(run.mock.calls.length, 0, remoteUrl);
82 + continue;
83 + }
84 + assert.strictEqual(branch, "master", remoteUrl);
85 + assert.include(
86 + [...(run.mock.calls[0]?.[0].args ?? [])],
87 + `--repository=${repository}`,
88 + remoteUrl,
89 + );
90 + }
91 + }).pipe(Effect.provide(AzureDevOpsCli.layer.pipe(Layer.provide(support))));
92 +});
93 +
94 it.effect(
95 "looks up a branch's pull requests a full page at a time, past forks' same-named branches",
96 () =>
packages/source-control-azure-devops/src/server/AzureDevOpsSourceControlProvider.ts
+20 -1
@@ -53,6 +53,22 @@ export const discovery = {
53 "Install the Azure command-line tools (`az`), then enable Azure DevOps support with `az extension add --name azure-devops`.",
54 } satisfies SourceControlCliDiscoverySpec;
55
56 +/**
57 + * The repository name a remote ends in; `az` takes it decoded and finds org and project itself.
58 + * Azure clone URLs carry no `.git` suffix, so a trailing `.git` is part of the name.
59 + */
60 +function repositoryNameFromRemote(remoteUrl: string): string | null {
61 + const path = URL.parse(remoteUrl.trim())?.pathname ?? remoteUrl.trim();
62 + const encoded = path.replace(/\/+$/u, "").split(/[/:]/u).at(-1);
63 + if (!encoded) return null;
64 + let name = encoded;
65 + try {
66 + name = decodeURIComponent(encoded);
67 + } catch {}
68 + // `az` replaces any argument value starting with `@` by the contents of that local file.
69 + return name.startsWith("@") ? null : name;
70 +}
71 +
72 function toChangeRequest(summary: NormalizedAzureDevOpsPullRequestRecord): ChangeRequest {
73 return {
74 provider: SourceControlProviderKind.make("azure-devops"),
@@ -205,7 +221,10 @@ export const make = Effect.gen(function* () {
221 ),
222 getDefaultBranch: Effect.fn("AzureDevOpsSourceControlProvider.getDefaultBranch")(
223 function (input) {
208 - return azure.getDefaultBranch({ cwd: input.cwd }).pipe(
224 + const repository =
225 + input.context === undefined ? null : repositoryNameFromRemote(input.context.remoteUrl);
226 + if (repository === null) return Effect.succeed(null);
227 + return azure.getDefaultBranch({ cwd: input.cwd, repository }).pipe(
228 Effect.mapError(
229 (error) =>
230 new SourceControlProviderError({