@devries-cameron20 / t3code-1 / commits / 83ee1f5d48
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(azure-devops): local pull request checkout no longer fails on --detect (#31170)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Pavel Kroupa committed Nov 14, 2026 at 02:58 UTC 83ee1f5d4862c72a06adc583c4acc7591230c59f
3 files changed +98 -36
packages/source-control-azure-devops/src/server/AzureDevOpsCli.ts
-23
@@ -261,12 +261,6 @@ export class AzureDevOpsCli extends Context.Service<
261 readonly cwd: string;
262 readonly repository: string;
263 }) => Effect.Effect<string | null, AzureDevOpsCliError>;
264 -
265 - readonly checkoutPullRequest: (input: {
266 - readonly cwd: string;
267 - readonly reference: string;
268 - readonly remoteName?: string;
269 - }) => Effect.Effect<void, AzureDevOpsCliError>;
264 }
265 >()("@t3tools/source-control-azure-devops/server/AzureDevOpsCli") {}
266
@@ -611,23 +605,6 @@ export const make = Effect.gen(function* () {
605 Effect.map((repo) => normalizeDefaultBranch(repo.defaultBranch)),
606 );
607 }),
614 - checkoutPullRequest: Effect.fn("AzureDevOpsCli.checkoutPullRequest")(function (input) {
615 - return execute({
616 - cwd: input.cwd,
617 - args: [
618 - "repos",
619 - "pr",
620 - "checkout",
621 - "--only-show-errors",
622 - "--detect",
623 - "true",
624 - "--id",
625 - normalizeChangeRequestId(input.reference),
626 - "--remote-name",
627 - input.remoteName ?? "origin",
628 - ],
629 - }).pipe(Effect.asVoid);
630 - }),
608 });
609 });
610
packages/source-control-azure-devops/src/server/AzureDevOpsSourceControlProvider.test.ts
+67
@@ -112,3 +112,70 @@ it.effect(
112 ),
113 ),
114 );
115 +
116 +it.effect.each([
117 + [
118 + "creates a missing branch from the fetched head",
119 + [],
120 + ["fetchRemoteBranch:upstream/feature/x->feature/x"],
121 + ],
122 + ["fetches without resetting an existing branch", ["feature/x"], ["fetchRemoteTrackingBranch"]],
123 +] as const)("checks a pull request out with git and %s", ([, localBranches, fetches]) => {
124 + const calls: Array<string> = [];
125 + return Effect.gen(function* () {
126 + const provider = yield* AzureDevOpsSourceControlProvider.make;
127 + yield* provider.checkoutChangeRequest({
128 + cwd: "/repo",
129 + reference: "42",
130 + context: {
131 + provider: {
132 + kind: SourceControlProviderKind.make("azure-devops"),
133 + name: "Azure DevOps",
134 + baseUrl: "https://dev.azure.com",
135 + },
136 + remoteName: "upstream",
137 + remoteUrl: "https://dev.azure.com/acme/project/_git/repo",
138 + },
139 + });
140 + assert.deepStrictEqual(calls, [...fetches, "switchRef:feature/x"]);
141 + }).pipe(
142 + Effect.provide(
143 + Layer.mergeAll(
144 + Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({
145 + getPullRequest: () =>
146 + Effect.succeed({
147 + number: 42,
148 + title: "Change",
149 + url: "https://dev.azure.com/acme/project/_git/repo/pullrequest/42",
150 + baseRefName: "main",
151 + headRefName: "feature/x",
152 + state: "open",
153 + isCrossRepository: false,
154 + closedAt: null,
155 + mergedAt: null,
156 + updatedAt: Option.none(),
157 + }),
158 + }),
159 + TestSourceControlHost.layer({
160 + git: {
161 + listLocalBranchNames: () => Effect.succeed([...localBranches]),
162 + fetchRemoteBranch: (input) => {
163 + calls.push(
164 + `fetchRemoteBranch:${input.remoteName}/${input.remoteBranch}->${input.localBranch}`,
165 + );
166 + return Effect.void;
167 + },
168 + fetchRemoteTrackingBranch: () => {
169 + calls.push("fetchRemoteTrackingBranch");
170 + return Effect.void;
171 + },
172 + switchRef: (input) => {
173 + calls.push(`switchRef:${input.refName}`);
174 + return Effect.succeed({ refName: input.refName });
175 + },
176 + },
177 + }),
178 + ),
179 + ),
180 + );
181 +});
packages/source-control-azure-devops/src/server/AzureDevOpsSourceControlProvider.ts
+31 -13
@@ -262,18 +262,37 @@ export const make = Effect.gen(function* () {
262 );
263 },
264 ),
265 + // `az repos pr checkout` ignores git failures: in a single-branch clone its checkout fails
266 + // and its pull then merges the pull request into the current branch.
267 checkoutChangeRequest: Effect.fn("AzureDevOpsSourceControlProvider.checkoutChangeRequest")(
266 - function (input) {
267 - return azure
268 - .checkoutPullRequest({
268 + function* (input) {
269 + const pullRequest = yield* azure.getPullRequest(input);
270 + if (pullRequest.isCrossRepository)
271 + return yield* new SourceControlProviderError({
272 + provider: SourceControlProviderKind.make("azure-devops"),
273 + operation: "checkoutChangeRequest",
274 cwd: input.cwd,
270 - reference: input.reference,
271 - ...(input.context !== undefined ? { remoteName: input.context.remoteName } : {}),
272 - })
273 - .pipe(
274 - Effect.mapError(
275 - (error) =>
276 - new SourceControlProviderError({
275 + reference: SourceControlProvider.transportSafeSourceControlErrorValue(input.reference),
276 + detail: "Checking out an Azure DevOps pull request from a fork is not supported.",
277 + });
278 + const branch = pullRequest.headRefName;
279 + const remoteBranch = {
280 + cwd: input.cwd,
281 + remoteName: input.context?.remoteName ?? "origin",
282 + remoteBranch: branch,
283 + };
284 + // An existing branch is only switched to; the caller advances it without losing commits.
285 + if ((yield* git.listLocalBranchNames(input.cwd)).includes(branch))
286 + yield* git.fetchRemoteTrackingBranch(remoteBranch);
287 + else yield* git.fetchRemoteBranch({ ...remoteBranch, localBranch: branch });
288 + yield* git.switchRef({ cwd: input.cwd, refName: branch });
289 + },
290 + (effect, input) =>
291 + effect.pipe(
292 + Effect.mapError((error) =>
293 + error._tag === "SourceControlProviderError"
294 + ? error
295 + : new SourceControlProviderError({
296 provider: SourceControlProviderKind.make("azure-devops"),
297 operation: "checkoutChangeRequest",
298 command: error.command,
@@ -284,9 +303,8 @@ export const make = Effect.gen(function* () {
303 detail: error.detail,
304 cause: error,
305 }),
287 - ),
288 - );
289 - },
306 + ),
307 + ),
308 ),
309 });
310 });