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, 22:00 UTC
fix(vcs): stop Check out here from discarding local pull request work (#15036)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Oct 20, 2026 at 05:42 UTC
23b550dde920828070bda1e707b1575d70763f5e
23 files changed
+484
-55
apps/server/src/git/GitManager.test.ts
+334
-2
@@ -103,11 +103,14 @@ interface FakeGhScenario {
103
isCrossRepository?: boolean;
104
headRepositoryNameWithOwner?: string | null;
105
headRepositoryOwnerLogin?: string | null;
106
+ headSha?: string;
107
};
108
repositoryCloneUrls?: Record<string, { url: string; sshUrl: string }>;
109
failWith?: string;
110
failCause?: unknown;
111
failAfterCalls?: number;
112
+ /** Check out the pull request head the way gh does: fast-forward only unless forced. */
113
+ syncCheckoutWithPullHead?: boolean;
114
}
115
116
function fakeGhOutput(stdout: string): VcsProcess.VcsProcessOutput {
@@ -514,7 +517,29 @@ function createGitHubProviderWithFakeGh(scenario: FakeGhScenario = {}): {
517
return Effect.try({
518
try: () => {
519
const headBranch = scenario.pullRequest?.headRefName;
517
- if (headBranch) {
520
+ if (headBranch && scenario.syncCheckoutWithPullHead) {
521
+ runGitSyncForFakeGh(input.cwd, [
522
+ "fetch",
523
+ "origin",
524
+ `refs/pull/${scenario.pullRequest?.number}/head`,
525
+ ]);
526
+ const existingBranch = NodeChildProcess.spawnSync(
527
+ "git",
528
+ ["show-ref", "--verify", "--quiet", `refs/heads/${headBranch}`],
529
+ { cwd: input.cwd },
530
+ );
531
+ if (existingBranch.status === 0) {
532
+ runGitSyncForFakeGh(input.cwd, ["checkout", headBranch]);
533
+ runGitSyncForFakeGh(
534
+ input.cwd,
535
+ args.includes("--force")
536
+ ? ["reset", "--hard", "FETCH_HEAD"]
537
+ : ["merge", "--ff-only", "FETCH_HEAD"],
538
+ );
539
+ } else {
540
+ runGitSyncForFakeGh(input.cwd, ["checkout", "-b", headBranch, "FETCH_HEAD"]);
541
+ }
542
+ } else if (headBranch) {
543
const existingBranch = NodeChildProcess.spawnSync(
544
"git",
545
["show-ref", "--verify", "--quiet", `refs/heads/${headBranch}`],
@@ -6261,10 +6286,317 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
6286
expect(result.worktreePath).toBeNull();
6287
const branch = (yield* runGit(repoDir, ["branch", "--show-current"])).stdout.trim();
6288
expect(branch).toBe("feature/pr-local");
6264
- expect(ghCalls).toContain("pr checkout 64 --force");
6289
+ expect(ghCalls).toContain("pr checkout 64");
6290
+ }),
6291
+ );
6292
+
6293
+ const setUpLocalCheckoutPullRequest = Effect.fnUntraced(function* (
6294
+ reportedHead: (pullHead: string) => string | undefined = (pullHead) => pullHead,
6295
+ syncCheckoutWithPullHead = true,
6296
+ gitSpawnGate?: NonNullable<Parameters<typeof makeManager>[0]>["gitSpawnGate"],
6297
+ ) {
6298
+ const repoDir = yield* makeTempDir("t3code-git-manager-");
6299
+ yield* initRepo(repoDir);
6300
+ const remoteDir = yield* createBareRemote();
6301
+ yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
6302
+ yield* runGit(repoDir, ["push", "-u", "origin", "main"]);
6303
+ yield* runGit(repoDir, ["checkout", "-b", "feature/pr-safe"]);
6304
+ NodeFS.writeFileSync(NodePath.join(repoDir, "pr.txt"), "first\n");
6305
+ yield* runGit(repoDir, ["add", "pr.txt"]);
6306
+ yield* runGit(repoDir, ["commit", "-m", "PR first"]);
6307
+ const firstCommit = (yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim();
6308
+ NodeFS.writeFileSync(NodePath.join(repoDir, "pr.txt"), "second\n");
6309
+ yield* runGit(repoDir, ["commit", "-am", "PR second"]);
6310
+ const pullHead = (yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim();
6311
+ yield* runGit(repoDir, ["push", "origin", "HEAD:refs/pull/91/head"]);
6312
+ yield* runGit(repoDir, ["reset", "--hard", firstCommit]);
6313
+ const headSha = reportedHead(pullHead);
6314
+ const { manager, ghCalls } = yield* makeManager({
6315
+ ...(gitSpawnGate ? { gitSpawnGate } : {}),
6316
+ ghScenario: {
6317
+ pullRequest: {
6318
+ number: 91,
6319
+ title: "Safe checkout PR",
6320
+ url: "https://github.com/pingdotgg/codething-mvp/pull/91",
6321
+ baseRefName: "main",
6322
+ headRefName: "feature/pr-safe",
6323
+ state: "open",
6324
+ ...(headSha === undefined ? {} : { headSha }),
6325
+ },
6326
+ syncCheckoutWithPullHead,
6327
+ },
6328
+ });
6329
+ return { repoDir, manager, ghCalls, firstCommit, pullHead };
6330
+ });
6331
+
6332
+ it.effect.each(["switch", "create-and-switch", "feature-branch"] as const)(
6333
+ "local PR checkout excludes a concurrent %s from a nested project with an alternate root",
6334
+ (operation) =>
6335
+ Effect.gen(function* () {
6336
+ const gate = {
6337
+ matches: (args: ReadonlyArray<string>) =>
6338
+ args[0] === "rev-parse" && args[1] === "--verify" && args[2] === "HEAD^{commit}",
6339
+ reached: yield* Deferred.make<void>(),
6340
+ release: yield* Deferred.make<void>(),
6341
+ };
6342
+ const { repoDir, manager, pullHead } = yield* setUpLocalCheckoutPullRequest(
6343
+ (head) => head,
6344
+ false,
6345
+ gate,
6346
+ );
6347
+ const nestedCwd = NodePath.join(repoDir, "nested-project");
6348
+ yield* makeDirectory(nestedCwd);
6349
+ const mainCommit = (yield* runGit(repoDir, ["rev-parse", "main"])).stdout.trim();
6350
+ yield* runGit(repoDir, ["checkout", "main"]);
6351
+ const registry = yield* Layer.build(
6352
+ VcsDriverRegistry.layer.pipe(
6353
+ Layer.provide(VcsProjectConfig.layer),
6354
+ Layer.provide(VcsProcess.layer),
6355
+ ),
6356
+ );
6357
+ const handle = yield* Context.get(registry, VcsDriverRegistry.VcsDriverRegistry).resolve({
6358
+ cwd: repoDir,
6359
+ });
6360
+ const resolvedHandle = {
6361
+ ...handle,
6362
+ repository: { ...handle.repository, rootPath: `${handle.repository.rootPath}/.` },
6363
+ };
6364
+ const fileSystem = yield* FileSystem.FileSystem;
6365
+ const canonicalRoot = yield* fileSystem.realPath(resolvedHandle.repository.rootPath);
6366
+ const git = yield* GitVcsDriver.GitVcsDriver;
6367
+ const events: string[] = [];
6368
+ const workflows = yield* Effect.forEach([0, 1], () =>
6369
+ GitWorkflowService.make.pipe(
6370
+ // Cache the real filesystem result so startImmediately reaches lease acquisition.
6371
+ Effect.provideService(FileSystem.FileSystem, {
6372
+ ...fileSystem,
6373
+ realPath: (root) =>
6374
+ root === resolvedHandle.repository.rootPath
6375
+ ? Effect.succeed(canonicalRoot)
6376
+ : fileSystem.realPath(root),
6377
+ }),
6378
+ Effect.provideService(GitManager.GitManager, {
6379
+ ...manager,
6380
+ runStackedAction: (input, options) =>
6381
+ Effect.sync(() => {
6382
+ events.push("feature-branch");
6383
+ NodeFS.writeFileSync(
6384
+ NodePath.join(repoDir, "second-client.txt"),
6385
+ "second client\n",
6386
+ );
6387
+ }).pipe(Effect.andThen(manager.runStackedAction(input, options))),
6388
+ }),
6389
+ Effect.provideService(VcsDriverRegistry.VcsDriverRegistry, {
6390
+ ...Context.get(registry, VcsDriverRegistry.VcsDriverRegistry),
6391
+ resolve: ({ cwd }) => Effect.succeed(cwd === repoDir ? handle : resolvedHandle),
6392
+ }),
6393
+ Effect.provideService(GitVcsDriver.GitVcsDriver, {
6394
+ ...git,
6395
+ switchRef: (input) =>
6396
+ Effect.sync(() => events.push("switch")).pipe(Effect.andThen(git.switchRef(input))),
6397
+ createRef: (input) =>
6398
+ Effect.sync(() => events.push("create-and-switch")).pipe(
6399
+ Effect.andThen(git.createRef(input)),
6400
+ ),
6401
+ }),
6402
+ ),
6403
+ );
6404
+ const preparing = yield* Effect.forkChild(
6405
+ workflows[0]!.preparePullRequestThread({ cwd: repoDir, reference: "91", mode: "local" }),
6406
+ );
6407
+ yield* Deferred.await(gate.reached);
6408
+ const switching = yield* Effect.forkChild(
6409
+ operation === "switch"
6410
+ ? workflows[1]!.switchRef({ cwd: nestedCwd, refName: "main" })
6411
+ : operation === "create-and-switch"
6412
+ ? workflows[1]!.createRef({
6413
+ cwd: nestedCwd,
6414
+ refName: "second-client",
6415
+ switchRef: true,
6416
+ })
6417
+ : workflows[1]!.runStackedAction({
6418
+ cwd: nestedCwd,
6419
+ actionId: "second-client-feature-branch",
6420
+ action: "commit",
6421
+ featureBranch: true,
6422
+ commitMessage: "Second client commit",
6423
+ }),
6424
+ { startImmediately: true },
6425
+ );
6426
+ // Both independent server workflows have started, but the second cannot touch Git yet.
6427
+ expect(events).toEqual([]);
6428
+ yield* Deferred.succeed(gate.release, undefined);
6429
+ const prepared = yield* Fiber.join(preparing);
6430
+ const switched = yield* Fiber.join(switching);
6431
+ expect(events).toEqual([operation]);
6432
+ expect(prepared).toMatchObject({ branch: "feature/pr-safe", isOnPullRequestHead: true });
6433
+ expect((yield* runGit(repoDir, ["rev-parse", "main"])).stdout.trim()).toBe(mainCommit);
6434
+ expect((yield* runGit(repoDir, ["rev-parse", "feature/pr-safe"])).stdout.trim()).toBe(
6435
+ pullHead,
6436
+ );
6437
+ expect((yield* runGit(repoDir, ["branch", "--show-current"])).stdout.trim()).toBe(
6438
+ operation === "switch"
6439
+ ? "main"
6440
+ : "branch" in switched
6441
+ ? switched.branch.name
6442
+ : "second-client",
6443
+ );
6444
+ if ("commit" in switched) {
6445
+ expect(switched.commit.status).toBe("created");
6446
+ expect((yield* runGit(repoDir, ["rev-parse", "HEAD^"])).stdout.trim()).toBe(pullHead);
6447
+ }
6448
+ }),
6449
+ );
6450
+
6451
+ it.effect.each([false, true])(
6452
+ "local PR checkout refuses and preserves tracked edits (staged: %s)",
6453
+ (staged) =>
6454
+ Effect.gen(function* () {
6455
+ const { repoDir, manager, ghCalls, firstCommit } = yield* setUpLocalCheckoutPullRequest();
6456
+ NodeFS.writeFileSync(NodePath.join(repoDir, "README.md"), "my unsaved edit\n");
6457
+ if (staged) {
6458
+ yield* runGit(repoDir, ["add", "README.md"]);
6459
+ }
6460
+ const beforeStatus = (yield* runGit(repoDir, ["status", "--porcelain"])).stdout;
6461
+
6462
+ const error = yield* preparePullRequestThread(manager, {
6463
+ cwd: repoDir,
6464
+ reference: "91",
6465
+ mode: "local",
6466
+ }).pipe(Effect.flip);
6467
+
6468
+ expect(error.message).toContain("uncommitted changes");
6469
+ expect(NodeFS.readFileSync(NodePath.join(repoDir, "README.md"), "utf8")).toBe(
6470
+ "my unsaved edit\n",
6471
+ );
6472
+ expect((yield* runGit(repoDir, ["status", "--porcelain"])).stdout).toBe(beforeStatus);
6473
+ expect((yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim()).toBe(firstCommit);
6474
+ expect(ghCalls.some((call) => call.startsWith("pr checkout"))).toBe(false);
6475
+ }),
6476
+ );
6477
+
6478
+ it.effect("local PR checkout refuses a diverged branch and keeps its extra commit", () =>
6479
+ Effect.gen(function* () {
6480
+ const { repoDir, manager, ghCalls } = yield* setUpLocalCheckoutPullRequest();
6481
+ NodeFS.writeFileSync(NodePath.join(repoDir, "mine.txt"), "mine\n");
6482
+ yield* runGit(repoDir, ["add", "mine.txt"]);
6483
+ yield* runGit(repoDir, ["commit", "-m", "My unpublished commit"]);
6484
+ const localCommit = (yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim();
6485
+ yield* runGit(repoDir, ["checkout", "main"]);
6486
+
6487
+ const error = yield* preparePullRequestThread(manager, {
6488
+ cwd: repoDir,
6489
+ reference: "91",
6490
+ mode: "local",
6491
+ }).pipe(Effect.flip);
6492
+
6493
+ // gh's fast-forward-only update fails rather than resetting the branch.
6494
+ expect(error.message).toContain("GitHub request failed");
6495
+ expect(ghCalls).toContain("pr checkout 91");
6496
+ expect((yield* runGit(repoDir, ["rev-parse", "feature/pr-safe"])).stdout.trim()).toBe(
6497
+ localCommit,
6498
+ );
6499
+ expect((yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim()).toBe(localCommit);
6500
+ expect(NodeFS.readFileSync(NodePath.join(repoDir, "mine.txt"), "utf8")).toBe("mine\n");
6501
}),
6502
);
6503
6504
+ it.effect.each([false, true])(
6505
+ "local PR checkout lands cleanly (existing branch: %s)",
6506
+ (existing) =>
6507
+ Effect.gen(function* () {
6508
+ const { repoDir, manager, pullHead } = yield* setUpLocalCheckoutPullRequest();
6509
+ yield* runGit(repoDir, ["checkout", "main"]);
6510
+ if (!existing) {
6511
+ yield* runGit(repoDir, ["branch", "-D", "feature/pr-safe"]);
6512
+ }
6513
+ NodeFS.writeFileSync(NodePath.join(repoDir, "untracked.txt"), "keep me\n");
6514
+
6515
+ const result = yield* preparePullRequestThread(manager, {
6516
+ cwd: repoDir,
6517
+ reference: "91",
6518
+ mode: "local",
6519
+ });
6520
+
6521
+ expect(result).toMatchObject({
6522
+ branch: "feature/pr-safe",
6523
+ worktreePath: null,
6524
+ isOnPullRequestHead: true,
6525
+ });
6526
+ expect((yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim()).toBe(pullHead);
6527
+ expect(NodeFS.readFileSync(NodePath.join(repoDir, "untracked.txt"), "utf8")).toBe(
6528
+ "keep me\n",
6529
+ );
6530
+ }),
6531
+ );
6532
+
6533
+ it.effect("local PR checkout fast-forwards a branch the host's checkout only switched to", () =>
6534
+ Effect.gen(function* () {
6535
+ // Like Bitbucket or Forgejo without `force`: the existing branch is checked out as it was.
6536
+ const { repoDir, manager, firstCommit, pullHead } = yield* setUpLocalCheckoutPullRequest(
6537
+ (head) => head.slice(0, 12),
6538
+ false,
6539
+ );
6540
+ yield* runGit(repoDir, ["checkout", "main"]);
6541
+ expect((yield* runGit(repoDir, ["rev-parse", "feature/pr-safe"])).stdout.trim()).toBe(
6542
+ firstCommit,
6543
+ );
6544
+
6545
+ const result = yield* preparePullRequestThread(manager, {
6546
+ cwd: repoDir,
6547
+ reference: "91",
6548
+ mode: "local",
6549
+ });
6550
+
6551
+ expect(result).toMatchObject({ branch: "feature/pr-safe", isOnPullRequestHead: true });
6552
+ expect((yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim()).toBe(pullHead);
6553
+ }),
6554
+ );
6555
+
6556
+ it.effect(
6557
+ "local PR checkout keeps a branch that is ahead and reports it is not on the head",
6558
+ () =>
6559
+ Effect.gen(function* () {
6560
+ const { repoDir, manager, pullHead } = yield* setUpLocalCheckoutPullRequest();
6561
+ yield* runGit(repoDir, ["reset", "--hard", pullHead]);
6562
+ NodeFS.writeFileSync(NodePath.join(repoDir, "mine.txt"), "mine\n");
6563
+ yield* runGit(repoDir, ["add", "mine.txt"]);
6564
+ yield* runGit(repoDir, ["commit", "-m", "My unpublished commit"]);
6565
+ const localCommit = (yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim();
6566
+ yield* runGit(repoDir, ["checkout", "main"]);
6567
+
6568
+ const result = yield* preparePullRequestThread(manager, {
6569
+ cwd: repoDir,
6570
+ reference: "91",
6571
+ mode: "local",
6572
+ });
6573
+
6574
+ expect(result).toMatchObject({ branch: "feature/pr-safe", isOnPullRequestHead: false });
6575
+ expect((yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim()).toBe(localCommit);
6576
+ expect(NodeFS.readFileSync(NodePath.join(repoDir, "mine.txt"), "utf8")).toBe("mine\n");
6577
+ }),
6578
+ );
6579
+
6580
+ it.effect.each([undefined, "0".repeat(40)])(
6581
+ "local PR checkout cannot confirm an unavailable provider head (%s)",
6582
+ (reportedHead) =>
6583
+ Effect.gen(function* () {
6584
+ const { repoDir, manager, pullHead } = yield* setUpLocalCheckoutPullRequest(
6585
+ () => reportedHead,
6586
+ );
6587
+ yield* runGit(repoDir, ["checkout", "main"]);
6588
+
6589
+ const result = yield* preparePullRequestThread(manager, {
6590
+ cwd: repoDir,
6591
+ reference: "91",
6592
+ mode: "local",
6593
+ });
6594
+
6595
+ expect((yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim()).toBe(pullHead);
6596
+ expect(result.isOnPullRequestHead).toBe(false);
6597
+ }),
6598
+ );
6599
+
6600
it.effect(
6601
"restores same-repository upstream tracking after local PR checkout without a remote ref",
6602
() =>
apps/server/src/git/GitManager.ts
+35
-4
@@ -2719,6 +2719,36 @@ export const make = Effect.gen(function* () {
2719
return { pullRequest };
2720
});
2721
2722
+ const ensureNoTrackedChanges = Effect.fn("ensureNoTrackedChanges")(function* (
2723
+ cwd: string,
2724
+ pullRequestNumber: number,
2725
+ ) {
2726
+ const trackedChanges = yield* gitCore.execute({
2727
+ operation: "GitManager.preparePullRequestThread.trackedChanges",
2728
+ cwd,
2729
+ args: ["status", "--porcelain", "--untracked-files=no"],
2730
+ });
2731
+ if (trackedChanges.stdout.trim().length > 0) {
2732
+ return yield* new GitManagerError({
2733
+ operation: "preparePullRequestThread",
2734
+ cwd,
2735
+ detail: `This repository has uncommitted changes. Commit or stash them before checking out pull request #${pullRequestNumber} here, or check it out in its own folder.`,
2736
+ });
2737
+ }
2738
+ });
2739
+
2740
+ // Some hosts only switch branches on checkout; use the existing lossless refresh to advance them.
2741
+ const moveToPullRequestHead = (cwd: string, headSha: string | undefined) =>
2742
+ headSha === undefined || !/^[0-9a-f]{7,64}$/i.test(headSha)
2743
+ ? Effect.succeed(false)
2744
+ : gitCore.resolveCommit({ cwd, revision: headSha }).pipe(
2745
+ Effect.flatMap(({ commitSha }) =>
2746
+ gitCore.refreshCheckedOutBranch({ cwd, targetCommit: commitSha }),
2747
+ ),
2748
+ Effect.map((refreshed) => refreshed.onTarget),
2749
+ Effect.orElseSucceed(() => false),
2750
+ );
2751
+
2752
const preparePullRequestThread: GitManager["Service"]["preparePullRequestThread"] = Effect.fn(
2753
"preparePullRequestThread",
2754
)(function* (input) {
@@ -2752,25 +2782,26 @@ export const make = Effect.gen(function* () {
2782
const pullRequest = toResolvedPullRequest(pullRequestSummary);
2783
2784
if (input.mode === "local") {
2785
+ yield* ensureNoTrackedChanges(input.cwd, pullRequest.number);
2786
yield* (yield* sourceControlProvider(input.cwd)).checkoutChangeRequest({
2787
cwd: input.cwd,
2788
reference: normalizedReference,
2758
- force: true,
2789
});
2790
const details = yield* gitCore.statusDetails(input.cwd);
2791
+ const branch = details.branch ?? pullRequest.headBranch;
2792
yield* configurePullRequestHeadUpstream(
2793
input.cwd,
2794
{
2795
...pullRequest,
2796
...toPullRequestHeadRemoteInfo(pullRequestSummary),
2797
},
2767
- details.branch ?? pullRequest.headBranch,
2798
+ branch,
2799
);
2800
return {
2801
pullRequest,
2771
- branch: details.branch ?? pullRequest.headBranch,
2802
+ branch,
2803
worktreePath: null,
2773
- isOnPullRequestHead: true,
2804
+ isOnPullRequestHead: yield* moveToPullRequestHead(input.cwd, pullRequestSummary.headSha),
2805
};
2806
}
2807
apps/server/src/git/GitWorkflowService.test.ts
+2
-2
@@ -1,4 +1,4 @@
1
-import { assert, describe, expect, it, vi } from "@effect/vitest";
1
+import { assert, expect, it, vi } from "@effect/vitest";
2
import * as DateTime from "effect/DateTime";
3
import * as Effect from "effect/Effect";
4
import * as Layer from "effect/Layer";
@@ -30,7 +30,7 @@ function layer(input: {
30
);
31
}
32
33
-describe("GitWorkflowService", () => {
33
+it.layer(NodeServices.layer)("GitWorkflowService", (it) => {
34
it.effect("reports a non-Git VCS repository as not a Git repository", () =>
35
Effect.gen(function* () {
36
const workflow = yield* GitWorkflowService.GitWorkflowService;
apps/server/src/git/GitWorkflowService.ts
+39
-7
@@ -1,6 +1,7 @@
1
import * as Context from "effect/Context";
2
import * as Effect from "effect/Effect";
3
import * as Layer from "effect/Layer";
4
+import * as FileSystem from "effect/FileSystem";
5
6
import {
7
GitManagerError,
@@ -31,6 +32,7 @@ import {
32
import * as GitManager from "./GitManager.ts";
33
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
34
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
35
+import { withWorkspaceLease } from "../workspace/workspaceLease.ts";
36
37
export class GitWorkflowService extends Context.Service<
38
GitWorkflowService,
@@ -171,6 +173,14 @@ export const make = Effect.gen(function* () {
173
const registry = yield* VcsDriverRegistry.VcsDriverRegistry;
174
const git = yield* GitVcsDriver.GitVcsDriver;
175
const gitManager = yield* GitManager.GitManager;
176
+ const fileSystem = yield* FileSystem.FileSystem;
177
+
178
+ // Nested projects and path aliases must share the checkout's branch-mutation lease.
179
+ const withCheckoutLease = <A, E, R>(rootPath: string, effect: Effect.Effect<A, E, R>) =>
180
+ fileSystem.realPath(rootPath).pipe(
181
+ Effect.orElseSucceed(() => rootPath),
182
+ Effect.flatMap((cwd) => withWorkspaceLease(cwd, effect)),
183
+ );
184
185
const ensureGit = Effect.fn("GitWorkflowService.ensureGit")(function* (
186
operation: string,
@@ -194,6 +204,7 @@ export const make = Effect.gen(function* () {
204
detail: `The ${operation} workflow currently supports Git repositories only; detected ${handle.kind}. (${cwd})`,
205
});
206
}
207
+ return handle;
208
});
209
210
const ensureGitCommand = Effect.fn("GitWorkflowService.ensureGitCommand")(function* (
@@ -220,6 +231,7 @@ export const make = Effect.gen(function* () {
231
detail: `The ${operation} command currently supports Git repositories only; detected ${handle.kind}.`,
232
});
233
}
234
+ return handle;
235
});
236
237
const detectGitRepositoryForStatus = Effect.fn("GitWorkflowService.detectGitRepositoryForStatus")(
@@ -360,16 +372,30 @@ export const make = Effect.gen(function* () {
372
),
373
runStackedAction: (input, options) =>
374
ensureGit("GitWorkflowService.runStackedAction", input.cwd).pipe(
363
- Effect.andThen(gitManager.runStackedAction(input, options)),
375
+ Effect.flatMap((handle) =>
376
+ input.featureBranch
377
+ ? withCheckoutLease(
378
+ handle.repository.rootPath,
379
+ gitManager.runStackedAction(input, options),
380
+ )
381
+ : gitManager.runStackedAction(input, options),
382
+ ),
383
),
384
resolvePullRequest: routeGitManager(
385
"GitWorkflowService.resolvePullRequest",
386
gitManager.resolvePullRequest,
387
),
369
- preparePullRequestThread: routeGitManager(
370
- "GitWorkflowService.preparePullRequestThread",
371
- gitManager.preparePullRequestThread,
372
- ),
388
+ preparePullRequestThread: (input) =>
389
+ ensureGit("GitWorkflowService.preparePullRequestThread", input.cwd).pipe(
390
+ Effect.flatMap((handle) =>
391
+ input.mode === "local"
392
+ ? withCheckoutLease(
393
+ handle.repository.rootPath,
394
+ gitManager.preparePullRequestThread(input),
395
+ )
396
+ : gitManager.preparePullRequestThread(input),
397
+ ),
398
+ ),
399
listRefs: (input) =>
400
detectGitRepositoryForCommand("GitWorkflowService.listRefs", input.cwd).pipe(
401
Effect.flatMap((isGitRepository) =>
@@ -422,11 +448,17 @@ export const make = Effect.gen(function* () {
448
),
449
createRef: (input) =>
450
ensureGitCommand("GitWorkflowService.createRef", input.cwd).pipe(
425
- Effect.andThen(git.createRef(input)),
451
+ Effect.flatMap((handle) =>
452
+ input.switchRef
453
+ ? withCheckoutLease(handle.repository.rootPath, git.createRef(input))
454
+ : git.createRef(input),
455
+ ),
456
),
457
switchRef: (input) =>
458
ensureGitCommand("GitWorkflowService.switchRef", input.cwd).pipe(
429
- Effect.andThen(Effect.scoped(git.switchRef(input))),
459
+ Effect.flatMap((handle) =>
460
+ withCheckoutLease(handle.repository.rootPath, Effect.scoped(git.switchRef(input))),
461
+ ),
462
),
463
renameBranch: (input) =>
464
ensureGit("GitWorkflowService.renameBranch", input.cwd).pipe(
apps/web/src/components/PullRequestThreadDialog.test.ts
+2
@@ -82,6 +82,7 @@ vi.mock("~/state/git", () => ({
82
return AsyncResult.success({
83
branch: "feature/pr",
84
worktreePath: mode === "worktree" ? "/worktree" : null,
85
+ isOnPullRequestHead: true,
86
});
87
},
88
},
@@ -102,6 +103,7 @@ vi.mock("~/state/vcs", () => ({
103
vi.mock("./ui/button", () => ({ Button: "Button" }));
104
vi.mock("./ui/input", () => ({ Input: "Input" }));
105
vi.mock("./ui/spinner", () => ({ Spinner: "Spinner" }));
106
+vi.mock("./ui/toast", () => ({ toastManager: { add: vi.fn() } }));
107
vi.mock("./ui/dialog", () => ({
108
Dialog: "Dialog",
109
DialogDescription: "DialogDescription",
apps/web/src/components/PullRequestThreadDialog.tsx
+5
@@ -21,6 +21,7 @@ import { getSourceControlPresentation } from "~/sourceControlPresentation";
21
import { useEnvironmentQuery } from "~/state/query";
22
import { readEnvironmentScope, useEnvironmentScope } from "~/state/session";
23
import { vcsEnvironment } from "~/state/vcs";
24
+import { OFF_HEAD_PULL_REQUEST_CHECKOUT_TOAST } from "./pullRequest/pullRequestCheckoutToast";
25
import { Button } from "./ui/button";
26
import {
27
Dialog,
@@ -33,6 +34,7 @@ import {
34
} from "./ui/dialog";
35
import { Input } from "./ui/input";
36
import { Spinner } from "./ui/spinner";
37
+import { toastManager } from "./ui/toast";
38
39
interface PullRequestThreadDialogProps {
40
open: boolean;
@@ -171,6 +173,9 @@ export function PullRequestThreadDialog({
173
branch: result.value.branch,
174
worktreePath: result.value.worktreePath,
175
});
176
+ if (!result.value.isOnPullRequestHead) {
177
+ toastManager.add(OFF_HEAD_PULL_REQUEST_CHECKOUT_TOAST);
178
+ }
179
onOpenChange(false);
180
};
181
apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
+3
-8
@@ -77,6 +77,7 @@ import {
77
} from "~/keybindings";
78
import { primaryServerKeybindingsAtom } from "~/state/server";
79
import { usePullRequestDefaultMergeMethodResolver } from "./usePullRequestActions";
80
+import { OFF_HEAD_PULL_REQUEST_CHECKOUT_TOAST } from "./pullRequestCheckoutToast";
81
import { changeRequestRepositoryUrl, gitHubPullRequestBrowserUrl } from "~/lib/openPullRequestLink";
82
import { usePreparePullRequestThreadAction } from "~/lib/sourceControlActions";
83
import { cn } from "~/lib/utils";
@@ -1264,12 +1265,6 @@ export function PullRequestDetailPanel({
1265
return;
1266
}
1267
setHandoff(null);
1267
- const staleCheckoutToast = {
1268
- type: "warning",
1269
- title: "Checked out, but not on the latest commits",
1270
- description:
1271
- "The checkout could not be moved onto the pull request's latest commits, so the code there is older than the pull request. Uncommitted work or local commits keep it where it is.",
1272
- } as const;
1268
if (task === null) {
1269
toastManager.update(
1270
toastId,
@@ -1282,7 +1277,7 @@ export function PullRequestDetailPanel({
1277
? "This repository is on the pull request's branch, with a thread open on it."
1278
: "The pull request is in its own worktree, with a thread open on it.",
1279
}
1285
- : staleCheckoutToast,
1280
+ : OFF_HEAD_PULL_REQUEST_CHECKOUT_TOAST,
1281
);
1282
return;
1283
}
@@ -1295,7 +1290,7 @@ export function PullRequestDetailPanel({
1290
title: "Checkout ready",
1291
description: "The task is in the composer — read it over, then send.",
1292
}
1298
- : staleCheckoutToast,
1293
+ : OFF_HEAD_PULL_REQUEST_CHECKOUT_TOAST,
1294
);
1295
};
1296
apps/web/src/components/pullRequest/pullRequestCheckoutToast.ts
new
+6
@@ -0,0 +1,6 @@
1
+export const OFF_HEAD_PULL_REQUEST_CHECKOUT_TOAST = {
2
+ type: "warning",
3
+ title: "Checked out, but not confirmed on the latest commit",
4
+ description:
5
+ "This checkout could not be confirmed at the pull request's latest commit, so its code may differ. Local commits or uncommitted work keep a checkout where it is.",
6
+} as const;
apps/web/src/components/pullRequest/usePullRequestActions.ts
+3
-8
@@ -31,6 +31,7 @@ import type { ReviewCommentContext } from "~/reviewCommentContext";
31
import { pullRequestEnvironment } from "~/state/pullRequests";
32
33
import { toastManager } from "../ui/toast";
34
+import { OFF_HEAD_PULL_REQUEST_CHECKOUT_TOAST } from "./pullRequestCheckoutToast";
35
import {
36
checkoutFailureDescription,
37
handoffPrompt,
@@ -372,12 +373,6 @@ export function usePullRequestHandoffs({
373
return;
374
}
375
setHandoff(null);
375
- const staleCheckoutToast = {
376
- type: "warning",
377
- title: "Checked out, but not on the latest commits",
378
- description:
379
- "The checkout could not be moved onto the pull request's latest commits, so the code there is older than the pull request. Uncommitted work or local commits keep it where it is.",
380
- } as const;
376
if (task === null) {
377
toastManager.update(
378
toastId,
@@ -390,7 +385,7 @@ export function usePullRequestHandoffs({
385
? "This repository is on the pull request's branch, with a thread open on it."
386
: "The pull request is in its own worktree, with a thread open on it.",
387
}
393
- : staleCheckoutToast,
388
+ : OFF_HEAD_PULL_REQUEST_CHECKOUT_TOAST,
389
);
390
return;
391
}
@@ -403,7 +398,7 @@ export function usePullRequestHandoffs({
398
title: "Checkout ready",
399
description: "The task is in the composer — read it over, then send.",
400
}
406
- : staleCheckoutToast,
401
+ : OFF_HEAD_PULL_REQUEST_CHECKOUT_TOAST,
402
);
403
};
404
packages/source-control-azure-devops/src/server/AzureDevOpsCli.test.ts
+2
@@ -43,6 +43,7 @@ describe("AzureDevOpsCli.layer", () => {
43
title: "Add Azure provider",
44
sourceRefName: "refs/heads/feature/source-control",
45
targetRefName: "refs/heads/main",
46
+ lastMergeSourceCommit: { commitId: "a".repeat(40) },
47
status: "active",
48
creationDate: "2026-01-02T00:00:00.000Z",
49
closedDate: null,
@@ -67,6 +68,7 @@ describe("AzureDevOpsCli.layer", () => {
68
assert.strictEqual(result.url, "https://dev.azure.com/acme/project/_git/repo/pullrequest/42");
69
assert.strictEqual(result.baseRefName, "main");
70
assert.strictEqual(result.headRefName, "feature/source-control");
71
+ assert.strictEqual(result.headSha, "a".repeat(40));
72
assert.strictEqual(result.state, "open");
73
assert.deepStrictEqual(result.updatedAt._tag, Option.some(1)._tag);
74
assert.deepStrictEqual(mockRun.mock.calls.at(-1)?.[0], {
packages/source-control-azure-devops/src/server/AzureDevOpsSourceControlProvider.test.ts
+2
@@ -23,6 +23,7 @@ it.effect("maps Azure DevOps PR summaries into provider-neutral change requests"
23
url: "https://dev.azure.com/acme/project/_git/repo/pullrequest/42",
24
baseRefName: "main",
25
headRefName: "feature/source-control",
26
+ headSha: "a".repeat(40),
27
state: "closed",
28
isCrossRepository: false,
29
closedAt: "2026-08-23T10:00:00Z",
@@ -42,6 +43,7 @@ it.effect("maps Azure DevOps PR summaries into provider-neutral change requests"
43
url: "https://dev.azure.com/acme/project/_git/repo/pullrequest/42",
44
baseRefName: "main",
45
headRefName: "feature/source-control",
46
+ headSha: "a".repeat(40),
47
state: "closed",
48
closedAt: "2026-08-23T10:00:00Z",
49
mergedAt: null,
packages/source-control-azure-devops/src/server/AzureDevOpsSourceControlProvider.ts
+3
-13
@@ -3,6 +3,7 @@ import * as Effect from "effect/Effect";
3
import { SourceControlProviderError, type ChangeRequest } from "@t3tools/contracts";
4
5
import * as AzureDevOpsCli from "./AzureDevOpsCli.ts";
6
+import type { NormalizedAzureDevOpsPullRequestRecord } from "./azureDevOpsPullRequests.ts";
7
import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
8
import {
9
combinedAuthOutput,
@@ -54,19 +55,7 @@ export const discovery = {
55
"Install the Azure command-line tools (`az`), then enable Azure DevOps support with `az extension add --name azure-devops`.",
56
} satisfies SourceControlCliDiscoverySpec;
57
57
-function toChangeRequest(summary: {
58
- readonly number: number;
59
- readonly title: string;
60
- readonly url: string;
61
- readonly baseRefName: string;
62
- readonly headRefName: string;
63
- readonly state: "open" | "closed" | "merged";
64
- readonly isDraft?: boolean;
65
- readonly isCrossRepository: boolean;
66
- readonly closedAt?: string | null;
67
- readonly mergedAt?: string | null;
68
- readonly updatedAt: ChangeRequest["updatedAt"];
69
-}): ChangeRequest {
58
+function toChangeRequest(summary: NormalizedAzureDevOpsPullRequestRecord): ChangeRequest {
59
return {
60
provider: SourceControlProviderKind.make("azure-devops"),
61
number: summary.number,
@@ -74,6 +63,7 @@ function toChangeRequest(summary: {
63
url: summary.url,
64
baseRefName: summary.baseRefName,
65
headRefName: summary.headRefName,
66
+ ...(summary.headSha !== undefined ? { headSha: summary.headSha } : {}),
67
state: summary.state,
68
...(summary.isDraft === true ? { isDraft: true } : {}),
69
closedAt: summary.closedAt ?? null,
packages/source-control-azure-devops/src/server/azureDevOpsPullRequests.ts
+7
@@ -13,6 +13,7 @@ export interface NormalizedAzureDevOpsPullRequestRecord {
13
readonly url: string;
14
readonly baseRefName: string;
15
readonly headRefName: string;
16
+ readonly headSha?: string;
17
readonly state: "open" | "closed" | "merged";
18
readonly isDraft?: boolean;
19
readonly isCrossRepository: boolean;
@@ -38,6 +39,10 @@ const AzureDevOpsPullRequestSchema = Schema.Struct({
39
),
40
sourceRefName: TrimmedNonEmptyString,
41
targetRefName: TrimmedNonEmptyString,
42
+ /** The source branch's tip as of Azure's last merge evaluation: the pull request's head. */
43
+ lastMergeSourceCommit: Schema.optional(
44
+ Schema.NullOr(Schema.Struct({ commitId: Schema.optional(Schema.NullOr(Schema.String)) })),
45
+ ),
46
status: Schema.String,
47
isDraft: Schema.optional(Schema.Boolean),
48
/** `az` prints `null` for a pull request from the same repo. */
@@ -158,6 +163,7 @@ function normalizeAzureDevOpsPullRequestRecord(
163
raw: Schema.Schema.Type<typeof AzureDevOpsPullRequestSchema>,
164
): NormalizedAzureDevOpsPullRequestRecord {
165
const state = normalizeAzureDevOpsPullRequestState(raw.status);
166
+ const headSha = trimOptionalString(raw.lastMergeSourceCommit?.commitId);
167
const terminalAt = Option.match(raw.closedDate ?? Option.none(), {
168
onNone: () => null,
169
onSome: DateTime.formatIso,
@@ -168,6 +174,7 @@ function normalizeAzureDevOpsPullRequestRecord(
174
url: normalizeAzureDevOpsPullRequestUrl(raw),
175
baseRefName: normalizeRefName(raw.targetRefName),
176
headRefName: normalizeRefName(raw.sourceRefName),
177
+ ...(headSha ? { headSha } : {}),
178
state,
179
...(raw.isDraft === true ? { isDraft: true } : {}),
180
isCrossRepository: raw.forkSource != null,
packages/source-control-bitbucket/src/server/BitbucketSourceControlProvider.test.ts
+22
-11
@@ -3,9 +3,16 @@ import { assert, it } from "@effect/vitest";
3
import * as Effect from "effect/Effect";
4
import * as Layer from "effect/Layer";
5
import * as Option from "effect/Option";
6
+import * as Schema from "effect/Schema";
7
8
import * as BitbucketApi from "./BitbucketApi.ts";
9
import * as BitbucketSourceControlProvider from "./BitbucketSourceControlProvider.ts";
10
+import {
11
+ BitbucketPullRequestSchema,
12
+ normalizeBitbucketPullRequestRecord,
13
+} from "./bitbucketPullRequests.ts";
14
+
15
+const decodePullRequest = Schema.decodeEffect(BitbucketPullRequestSchema);
16
17
function makeProvider(bitbucket: Partial<BitbucketApi.BitbucketApi["Service"]>) {
18
return BitbucketSourceControlProvider.make.pipe(
@@ -17,18 +24,21 @@ it.effect("maps Bitbucket PR summaries into provider-neutral change requests", (
24
Effect.gen(function* () {
25
const provider = yield* makeProvider({
26
getPullRequest: () =>
20
- Effect.succeed({
21
- number: 42,
27
+ decodePullRequest({
28
+ id: 42,
29
title: "Add Bitbucket provider",
23
- url: "https://bitbucket.org/pingdotgg/t3code/pull-requests/42",
24
- baseRefName: "main",
25
- headRefName: "feature/source-control",
26
- state: "open",
27
- updatedAt: Option.none(),
28
- isCrossRepository: true,
29
- headRepositoryNameWithOwner: "fork/t3code",
30
- headRepositoryOwnerLogin: "fork",
31
- }),
30
+ links: { html: { href: "https://bitbucket.org/pingdotgg/t3code/pull-requests/42" } },
31
+ source: {
32
+ branch: { name: "feature/source-control" },
33
+ commit: { hash: "a".repeat(40) },
34
+ repository: { full_name: "fork/t3code" },
35
+ },
36
+ destination: {
37
+ branch: { name: "main" },
38
+ repository: { full_name: "pingdotgg/t3code" },
39
+ },
40
+ state: "OPEN",
41
+ }).pipe(Effect.orDie, Effect.map(normalizeBitbucketPullRequestRecord)),
42
});
43
44
const changeRequest = yield* provider.getChangeRequest({
@@ -43,6 +53,7 @@ it.effect("maps Bitbucket PR summaries into provider-neutral change requests", (
53
url: "https://bitbucket.org/pingdotgg/t3code/pull-requests/42",
54
baseRefName: "main",
55
headRefName: "feature/source-control",
56
+ headSha: "a".repeat(40),
57
state: "open",
58
updatedAt: Option.none(),
59
isCrossRepository: true,
packages/source-control-bitbucket/src/server/BitbucketSourceControlProvider.ts
+1
@@ -16,6 +16,7 @@ function toChangeRequest(summary: NormalizedBitbucketPullRequestRecord): ChangeR
16
url: summary.url,
17
baseRefName: summary.baseRefName,
18
headRefName: summary.headRefName,
19
+ ...(summary.headSha !== undefined ? { headSha: summary.headSha } : {}),
20
state: summary.state,
21
...(summary.isDraft === true ? { isDraft: true } : {}),
22
updatedAt: summary.updatedAt ?? Option.none(),
packages/source-control-bitbucket/src/server/bitbucketPullRequests.ts
+6
@@ -9,6 +9,7 @@ export interface NormalizedBitbucketPullRequestRecord {
9
readonly url: string;
10
readonly baseRefName: string;
11
readonly headRefName: string;
12
+ readonly headSha?: string;
13
readonly state: "open" | "closed" | "merged";
14
readonly isDraft?: boolean;
15
readonly updatedAt: Option.Option<DateTime.Utc>;
@@ -33,6 +34,9 @@ export const BitbucketPullRequestBranchSchema = Schema.Struct({
34
branch: Schema.Struct({
35
name: TrimmedNonEmptyString,
36
}),
37
+ commit: Schema.optional(
38
+ Schema.NullOr(Schema.Struct({ hash: Schema.optional(Schema.NullOr(Schema.String)) })),
39
+ ),
40
});
41
42
export const BitbucketPullRequestSchema = Schema.Struct({
@@ -85,6 +89,7 @@ export function normalizeBitbucketPullRequestRecord(
89
): NormalizedBitbucketPullRequestRecord {
90
const headRepositoryNameWithOwner = trimOptionalString(raw.source.repository?.full_name);
91
const baseRepositoryNameWithOwner = trimOptionalString(raw.destination.repository?.full_name);
92
+ const headSha = trimOptionalString(raw.source.commit?.hash);
93
const headRepositoryOwnerLogin = raw.source.repository
94
? repositoryOwner(raw.source.repository)
95
: null;
@@ -99,6 +104,7 @@ export function normalizeBitbucketPullRequestRecord(
104
url: raw.links.html.href,
105
baseRefName: raw.destination.branch.name,
106
headRefName: raw.source.branch.name,
107
+ ...(headSha ? { headSha } : {}),
108
state: normalizeBitbucketPullRequestState(raw.state),
109
...(raw.draft === true ? { isDraft: true } : {}),
110
updatedAt: raw.updated_on ?? Option.none(),
packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts
+1
@@ -555,6 +555,7 @@ it.effect("loads Forgejo pull request references from files and commits views",
555
const result = yield* provider.getChangeRequest({ cwd: "/repo", reference });
556
assert.strictEqual(result.number, 42);
557
assert.strictEqual(result.title, "Forgejo view reference");
558
+ assert.strictEqual(result.headSha, "head");
559
}
560
const invalid = yield* provider
561
.getChangeRequest({
packages/source-control-forgejo/src/server/forgejoPullRequests.ts
+1
@@ -35,6 +35,7 @@ export function toForgejoChangeRequest(raw: typeof ForgejoPullRequestSchema.Type
35
isDraft: raw.draft ?? /^(?:\[WIP\]|WIP:)/i.test(raw.title),
36
baseRefName: raw.base.ref,
37
headRefName: raw.head.ref,
38
+ ...(raw.head.sha.trim().length > 0 ? { headSha: raw.head.sha.trim() } : {}),
39
closedAt: raw.closed_at ?? null,
40
mergedAt: raw.merged_at ?? null,
41
updatedAt: raw.updated_at ?? Option.none(),
packages/source-control-gitlab/src/server/GitLabCli.test.ts
+2
@@ -40,6 +40,7 @@ layer("GitLabCli.layer", (it) => {
40
web_url: "https://gitlab.com/pingdotgg/t3code/-/merge_requests/42",
41
target_branch: "main",
42
source_branch: "feature/mr-threads",
43
+ sha: "a".repeat(40),
44
state: "closed",
45
closed_at: "2026-08-23T10:00:00Z",
46
source_project_id: 101,
@@ -66,6 +67,7 @@ layer("GitLabCli.layer", (it) => {
67
url: "https://gitlab.com/pingdotgg/t3code/-/merge_requests/42",
68
baseRefName: "main",
69
headRefName: "feature/mr-threads",
70
+ headSha: "a".repeat(40),
71
state: "closed",
72
closedAt: "2026-08-23T10:00:00Z",
73
mergedAt: null,
packages/source-control-gitlab/src/server/GitLabCli.ts
+1
@@ -244,6 +244,7 @@ export interface GitLabMergeRequestSummary {
244
readonly url: string;
245
readonly baseRefName: string;
246
readonly headRefName: string;
247
+ readonly headSha?: string;
248
readonly state?: "open" | "closed" | "merged";
249
readonly isDraft?: boolean;
250
readonly closedAt?: string | null;
packages/source-control-gitlab/src/server/GitLabSourceControlProvider.test.ts
+2
@@ -35,6 +35,7 @@ it.effect("maps GitLab MR summaries into provider-neutral change requests", () =
35
url: "https://gitlab.com/pingdotgg/t3code/-/merge_requests/42",
36
baseRefName: "main",
37
headRefName: "feature/source-control",
38
+ headSha: "a".repeat(40),
39
state: "closed",
40
closedAt: "2026-08-23T10:00:00Z",
41
isCrossRepository: true,
@@ -55,6 +56,7 @@ it.effect("maps GitLab MR summaries into provider-neutral change requests", () =
56
url: "https://gitlab.com/pingdotgg/t3code/-/merge_requests/42",
57
baseRefName: "main",
58
headRefName: "feature/source-control",
59
+ headSha: "a".repeat(40),
60
state: "closed",
61
closedAt: "2026-08-23T10:00:00Z",
62
mergedAt: null,
packages/source-control-gitlab/src/server/GitLabSourceControlProvider.ts
+1
@@ -35,6 +35,7 @@ function toChangeRequest(summary: GitLabCli.GitLabMergeRequestSummary): ChangeRe
35
url: summary.url,
36
baseRefName: summary.baseRefName,
37
headRefName: summary.headRefName,
38
+ ...(summary.headSha !== undefined ? { headSha: summary.headSha } : {}),
39
state: summary.state ?? "open",
40
...(summary.isDraft === true ? { isDraft: true } : {}),
41
closedAt: summary.closedAt ?? null,
packages/source-control-gitlab/src/server/gitLabMergeRequests.ts
+4
@@ -13,6 +13,7 @@ export interface NormalizedGitLabMergeRequestRecord {
13
readonly url: string;
14
readonly baseRefName: string;
15
readonly headRefName: string;
16
+ readonly headSha?: string;
17
readonly state: "open" | "closed" | "merged";
18
readonly isDraft?: boolean;
19
readonly closedAt?: string | null;
@@ -43,6 +44,7 @@ const GitLabMergeRequestSchema = Schema.Struct({
44
web_url: TrimmedNonEmptyString,
45
source_branch: TrimmedNonEmptyString,
46
target_branch: TrimmedNonEmptyString,
47
+ sha: Schema.optional(Schema.NullOr(Schema.String)),
48
state: Schema.optional(Schema.NullOr(Schema.String)),
49
draft: Schema.optional(Schema.Boolean),
50
work_in_progress: Schema.optional(Schema.Boolean),
@@ -107,6 +109,7 @@ function normalizeGitLabMergeRequestRecord(
109
? sourceProjectPath.toLowerCase() !== targetProjectPath.toLowerCase()
110
: undefined;
111
const headRepositoryOwnerLogin = ownerLoginFromPathWithNamespace(sourceProjectPath);
112
+ const headSha = trimOptionalString(raw.sha);
113
114
return {
115
number: raw.iid,
@@ -114,6 +117,7 @@ function normalizeGitLabMergeRequestRecord(
117
url: raw.web_url,
118
baseRefName: raw.target_branch,
119
headRefName: raw.source_branch,
120
+ ...(headSha ? { headSha } : {}),
121
state: normalizeGitLabMergeRequestState(raw.state),
122
...(raw.draft === true || raw.work_in_progress === true ? { isDraft: true } : {}),
123
closedAt: raw.closed_at ?? null,