@devries-cameron20 / t3code-1 / commits / 6e4ca6ce9d
Fork 0

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

fix(git): allow creating prs from dirty worktrees (#15625)

maria committed Oct 9, 2026 at 23:48 UTC 6e4ca6ce9d04009af290412b77a0acb9be9f8a18
6 files changed +42 -24
apps/server/src/git/GitManager.test.ts
+30 -2
@@ -3743,7 +3743,7 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
3743 }),
3744 );
3745
3746 - it.effect("create_pr pushes a clean branch before creating the PR when needed", () =>
3746 + it.effect("create_pr pushes committed changes while preserving a dirty worktree", () =>
3747 Effect.gen(function* () {
3748 const repoDir = yield* makeTempDir("t3code-git-manager-");
3749 yield* initRepo(repoDir);
@@ -3753,6 +3753,10 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
3753 NodeFS.writeFileSync(NodePath.join(repoDir, "create-pr-only.txt"), "create pr\n");
3754 yield* runGit(repoDir, ["add", "create-pr-only.txt"]);
3755 yield* runGit(repoDir, ["commit", "-m", "Create PR only branch"]);
3756 + const headBefore = (yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim();
3757 + NodeFS.writeFileSync(NodePath.join(repoDir, "README.md"), "uncommitted readme\n");
3758 + NodeFS.writeFileSync(NodePath.join(repoDir, "untracked.txt"), "untracked work\n");
3759 + const statusBefore = (yield* runGit(repoDir, ["status", "--porcelain"])).stdout;
3760
3761 const { manager, ghCalls } = yield* makeManager({
3762 ghScenario: {
@@ -3781,6 +3785,10 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
3785 expect(result.push.setUpstream).toBe(true);
3786 expect(result.pr.status).toBe("created");
3787 expect(result.pr.number).toBe(303);
3788 + expect((yield* runGit(repoDir, ["status", "--porcelain"])).stdout).toBe(statusBefore);
3789 + expect(
3790 + (yield* runGit(remoteDir, ["rev-parse", "feature/create-pr-only"])).stdout.trim(),
3791 + ).toBe(headBefore);
3792 expect(
3793 ghCalls.some((call) =>
3794 call.includes("pr create --base main --head feature/create-pr-only"),
@@ -6199,7 +6207,7 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
6207 }),
6208 );
6209
6202 - it.effect("create_pr emits only the PR phase when the branch is already pushed", () =>
6210 + it.effect("create_pr preserves dirty work on an already pushed branch", () =>
6211 Effect.gen(function* () {
6212 const repoDir = yield* makeTempDir("t3code-git-manager-");
6213 yield* initRepo(repoDir);
@@ -6210,8 +6218,22 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
6218 yield* runGit(repoDir, ["add", "pr-only.txt"]);
6219 yield* runGit(repoDir, ["commit", "-m", "PR only branch"]);
6220 yield* runGit(repoDir, ["push", "-u", "origin", "feature/pr-only-follow-up"]);
6221 + const headBefore = (yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout;
6222 + NodeFS.writeFileSync(NodePath.join(repoDir, "README.md"), "staged readme\n");
6223 + yield* runGit(repoDir, ["add", "README.md"]);
6224 + NodeFS.writeFileSync(NodePath.join(repoDir, "pr-only.txt"), "unstaged feature work\n");
6225 + NodeFS.writeFileSync(NodePath.join(repoDir, "untracked.txt"), "untracked work\n");
6226 + const statusBefore = (yield* runGit(repoDir, ["status", "--porcelain"])).stdout;
6227 + const stagedBefore = (yield* runGit(repoDir, ["diff", "--cached"])).stdout;
6228 + let generatedContent: TextGeneration.PrContentGenerationInput | undefined;
6229
6230 const { manager } = yield* makeManager({
6231 + textGeneration: {
6232 + generatePrContent: (input) => {
6233 + generatedContent = input;
6234 + return Effect.succeed({ title: "PR only branch", body: "Committed feature work" });
6235 + },
6236 + },
6237 ghScenario: {
6238 prListSequence: [
6239 JSON.stringify([]),
@@ -6251,6 +6273,12 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
6273 expect(result.commit.status).toBe("skipped_not_requested");
6274 expect(result.push.status).toBe("skipped_not_requested");
6275 expect(result.pr.status).toBe("created");
6276 + expect(generatedContent?.diffPatch).toContain("+pr only");
6277 + expect(generatedContent?.diffPatch).not.toContain("staged readme");
6278 + expect(generatedContent?.diffPatch).not.toContain("unstaged feature work");
6279 + expect((yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout).toBe(headBefore);
6280 + expect((yield* runGit(repoDir, ["status", "--porcelain"])).stdout).toBe(statusBefore);
6281 + expect((yield* runGit(repoDir, ["diff", "--cached"])).stdout).toBe(stagedBefore);
6282 expect(
6283 events.filter(
6284 (event): event is Extract<GitActionProgressEvent, { kind: "phase_started" }> =>
apps/server/src/git/GitManager.ts
-8
@@ -2730,14 +2730,6 @@ export const make = Effect.gen(function* () {
2730 detail: "Feature-branch checkout is only supported for commit actions.",
2731 });
2732 }
2733 - if (input.action === "create_pr" && initialStatus.hasWorkingTreeChanges) {
2734 - return yield* new GitManagerError({
2735 - operation: "runStackedAction",
2736 - cwd: input.cwd,
2737 - detail: "Commit local changes before creating a PR.",
2738 - });
2739 - }
2740 -
2733 const phases: GitActionProgressPhase[] = [
2734 ...(input.featureBranch ? (["branch"] as const) : []),
2735 ...(wantsCommit ? (["commit"] as const) : []),
apps/web/src/components/GitActionsControl.logic.test.ts
+9 -3
@@ -365,7 +365,7 @@ describe("when: source control provider uses merge requests", () => {
365 });
366
367 describe("when: ref is clean, up to date, and has no open PR", () => {
368 - it("enables create PR when synced with upstream but ahead of default", () => {
368 + it("enables create PR when synced with upstream but ahead of default, even with local changes", () => {
369 const syncedFeature = status({
370 aheadCount: 0,
371 behindCount: 0,
@@ -383,6 +383,12 @@ describe("when: ref is clean, up to date, and has no open PR", () => {
383
384 const items = buildMenuItems(syncedFeature, false);
385 assert.equal(items.find((item) => item.id === "pr")?.disabled, false);
386 +
387 + const dirtyFeature = { ...syncedFeature, hasWorkingTreeChanges: true };
388 + assert.equal(
389 + buildMenuItems(dirtyFeature, false).find((item) => item.id === "pr")?.disabled,
390 + false,
391 + );
392 });
393
394 it("resolveQuickAction returns disabled no-action state", () => {
@@ -550,7 +556,7 @@ describe("when: working tree has local changes", () => {
556 ]);
557 });
558
553 - it("buildMenuItems enables push for ahead commits while local changes remain uncommitted", () => {
559 + it("buildMenuItems enables push and create PR for ahead commits while local changes remain uncommitted", () => {
560 const items = buildMenuItems(
561 status({
562 refName: "feature/test",
@@ -584,7 +590,7 @@ describe("when: working tree has local changes", () => {
590 {
591 id: "pr",
592 label: "Create PR",
587 - disabled: true,
593 + disabled: false,
594 icon: "pr",
595 kind: "open_dialog",
596 dialogAction: "create_pr",
apps/web/src/components/GitActionsControl.logic.ts
-1
@@ -184,7 +184,6 @@ export function buildMenuItems(
184 const canCreatePr =
185 !isBusy &&
186 hasBranch &&
187 - !hasChanges &&
187 !hasOpenPr &&
188 hasDefaultBranchDelta &&
189 !isBehind &&
apps/web/src/components/GitActionsControl.tsx
+1 -4
@@ -338,13 +338,10 @@ function getMenuActionDisabledReason({
338 if (!hasBranch) {
339 return `Detached HEAD: check out a branch before creating a ${terminology.singular}.`;
340 }
341 - if (hasChanges) {
342 - return `Commit local changes before creating a ${terminology.singular}.`;
343 - }
341 if (!gitStatus.hasUpstream && !hasPrimaryRemote) {
342 return `Add an "origin" remote before creating a ${terminology.singular}.`;
343 }
347 - if (!isAhead) {
344 + if ((gitStatus.aheadOfDefaultCount ?? gitStatus.aheadCount) <= 0) {
345 return `No local commits to include in a ${terminology.singular}.`;
346 }
347 if (isBehind) {
packages/client-runtime/src/state/gitActions.ts
+2 -6
@@ -65,9 +65,8 @@ export function buildMenuItems(
65 const canCreatePr =
66 !isBusy &&
67 hasBranch &&
68 - !hasChanges &&
68 !hasOpenPr &&
70 - gitStatus.aheadCount > 0 &&
69 + (gitStatus.aheadOfDefaultCount ?? gitStatus.aheadCount) > 0 &&
70 !isBehind &&
71 (gitStatus.hasUpstream || canPushWithoutUpstream);
72 const canOpenPr = !isBusy && hasOpenPr;
@@ -292,13 +291,10 @@ export function getGitActionDisabledReason(input: {
291 if (!hasBranch) {
292 return "Detached HEAD: checkout a branch before creating a PR.";
293 }
295 - if (hasChanges) {
296 - return "Commit local changes before creating a PR.";
297 - }
294 if (!gitStatus.hasUpstream && !hasOriginRemote) {
295 return 'Add an "origin" remote before creating a PR.';
296 }
301 - if (!isAhead) {
297 + if ((gitStatus.aheadOfDefaultCount ?? gitStatus.aheadCount) <= 0) {
298 return "No local commits to include in a PR.";
299 }
300 if (isBehind) {