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

Enable push/PR actions for branches without upstream

- Treat no-upstream branches as publishable: enable Push/Create PR and update quick actions - Route Create PR menu action through commit+push+PR flow when appropriate - Simplify Git action dialog to commit-only and add "Commit on new branch" option

Julius Marminge committed Mar 1, 2026 at 10:58 UTC 02eca40c3b854377ec7bfff629c638379b04e030
3 files changed +125 -113
apps/web/src/components/GitActionsControl.logic.test.ts
+13 -11
@@ -515,19 +515,20 @@ describe("when: HEAD is detached and there are no local changes", () => {
515 });
516
517 describe("when: branch has no upstream configured", () => {
518 - it("resolveQuickAction returns disabled commit state when clean and no commits are ahead", () => {
518 + it("resolveQuickAction runs push and create PR when clean, no upstream, and no local commits are ahead", () => {
519 const quick = resolveQuickAction(
520 status({ hasUpstream: false, pr: null, aheadCount: 0 }),
521 false,
522 );
523 assert.deepInclude(quick, {
524 - kind: "show_hint",
525 - label: "Commit",
526 - disabled: true,
524 + kind: "run_action",
525 + action: "commit_push_pr",
526 + label: "Push & create PR",
527 + disabled: false,
528 });
529 });
530
530 - it("resolveQuickAction remains disabled when clean, no upstream, and no local commits ahead", () => {
531 + it("resolveQuickAction runs push when clean and no upstream even if PR metadata exists", () => {
532 const quick = resolveQuickAction(
533 status({
534 hasUpstream: false,
@@ -544,9 +545,10 @@ describe("when: branch has no upstream configured", () => {
545 false,
546 );
547 assert.deepInclude(quick, {
547 - kind: "show_hint",
548 - label: "Commit",
549 - disabled: true,
548 + kind: "run_action",
549 + action: "commit_push",
550 + label: "Push",
551 + disabled: false,
552 });
553 });
554
@@ -574,7 +576,7 @@ describe("when: branch has no upstream configured", () => {
576 });
577 });
578
577 - it("buildMenuItems disables push and create PR when no commits are ahead", () => {
579 + it("buildMenuItems enables push and create PR to publish branch when no upstream exists", () => {
580 const items = buildMenuItems(
581 status({ hasUpstream: false, pr: null, aheadCount: 0 }),
582 false,
@@ -591,7 +593,7 @@ describe("when: branch has no upstream configured", () => {
593 {
594 id: "push",
595 label: "Push",
594 - disabled: true,
596 + disabled: false,
597 icon: "push",
598 kind: "open_dialog",
599 dialogAction: "push",
@@ -599,7 +601,7 @@ describe("when: branch has no upstream configured", () => {
601 {
602 id: "pr",
603 label: "Create PR",
602 - disabled: true,
604 + disabled: false,
605 icon: "pr",
606 kind: "open_dialog",
607 dialogAction: "create_pr",
apps/web/src/components/GitActionsControl.logic.ts
+20 -3
@@ -111,15 +111,20 @@ export function buildMenuItems(
111 const hasChanges = gitStatus.hasWorkingTreeChanges;
112 const hasOpenPr = gitStatus.pr?.state === "open";
113 const isBehind = gitStatus.behindCount > 0;
114 + const canPublishUntrackedBranch = !gitStatus.hasUpstream;
115 const canCommit = !isBusy && hasChanges;
115 - const canPush = !isBusy && hasBranch && !hasChanges && !isBehind && gitStatus.aheadCount > 0;
116 + const canPush =
117 + !isBusy &&
118 + hasBranch &&
119 + !hasChanges &&
120 + !isBehind &&
121 + (gitStatus.aheadCount > 0 || canPublishUntrackedBranch);
122 const canCreatePr =
123 !isBusy &&
124 hasBranch &&
125 !hasChanges &&
126 !hasOpenPr &&
121 - gitStatus.aheadCount > 0 &&
122 - gitStatus.hasUpstream &&
127 + (gitStatus.aheadCount > 0 || canPublishUntrackedBranch) &&
128 !isBehind;
129 const canOpenPr = !isBusy && hasOpenPr;
130
@@ -205,6 +210,18 @@ export function resolveQuickAction(
210 };
211 }
212
213 + if (!gitStatus.hasUpstream) {
214 + if (hasOpenPr || isDefaultBranch) {
215 + return { label: "Push", disabled: false, kind: "run_action", action: "commit_push" };
216 + }
217 + return {
218 + label: "Push & create PR",
219 + disabled: false,
220 + kind: "run_action",
221 + action: "commit_push_pr",
222 + };
223 + }
224 +
225 if (isDiverged) {
226 return {
227 label: "Sync branch",
apps/web/src/components/GitActionsControl.tsx
+92 -99
@@ -8,7 +8,6 @@ import {
8 buildMenuItems,
9 type GitActionIconName,
10 type GitActionMenuItem,
11 - type GitDialogAction,
11 type GitQuickAction,
12 requiresDefaultBranchConfirmation,
13 resolveAutoFeatureBranchName,
@@ -88,6 +87,9 @@ function getMenuActionDisabledReason(
87 if (isBehind) {
88 return "Branch is behind upstream. Pull/rebase before pushing.";
89 }
90 + if (!gitStatus.hasUpstream) {
91 + return "Branch has no upstream. Push to publish it.";
92 + }
93 if (!isAhead) {
94 return "No local commits to push.";
95 }
@@ -103,29 +105,21 @@ function getMenuActionDisabledReason(
105 if (hasChanges) {
106 return "Commit local changes before creating a PR.";
107 }
106 - if (!isAhead) {
107 - return "No local commits to include in a PR.";
108 - }
108 if (!gitStatus.hasUpstream) {
109 return "Set an upstream branch before creating a PR.";
110 }
111 + if (!isAhead) {
112 + return "No local commits to include in a PR.";
113 + }
114 if (isBehind) {
115 return "Branch is behind upstream. Pull/rebase before creating a PR.";
116 }
117 return "Create PR is currently unavailable.";
118 }
119
118 -const DIALOG_TITLE_BY_ACTION = {
119 - commit: "Commit changes",
120 - push: "Push branch",
121 - create_pr: "Create pull request",
122 -};
123 -
124 -const DIALOG_DESCRIPTION_BY_ACTION = {
125 - commit: "Review and confirm your commit. Leave the message blank to auto-generate one.",
126 - push: "Push this branch now.",
127 - create_pr: "Create a pull request using generated title/body content.",
128 -};
120 +const COMMIT_DIALOG_TITLE = "Commit changes";
121 +const COMMIT_DIALOG_DESCRIPTION =
122 + "Review and confirm your commit. Leave the message blank to auto-generate one.";
123
124 const DEFAULT_BRANCH_ACTION_DESCRIPTION: Record<GitStackedAction, string> = {
125 commit: "commit changes",
@@ -158,7 +152,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
152 [activeThreadId],
153 );
154 const queryClient = useQueryClient();
161 - const [activeDialogAction, setActiveDialogAction] = useState<GitDialogAction | null>(null);
155 + const [isCommitDialogOpen, setIsCommitDialogOpen] = useState(false);
156 const [dialogCommitMessage, setDialogCommitMessage] = useState("");
157 const [pendingDefaultBranchAction, setPendingDefaultBranchAction] =
158 useState<PendingDefaultBranchAction | null>(null);
@@ -376,7 +370,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
370 children: "Create PR",
371 onClick: () => {
372 closeResultToast();
379 - setActiveDialogAction("create_pr");
373 + void runGitActionWithToast({ action: "commit_push_pr" });
374 },
375 },
376 }
@@ -396,7 +390,6 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
390 [
391 isDefaultBranch,
392 runImmediateGitActionMutation,
399 - setActiveDialogAction,
393 setPendingDefaultBranchAction,
394 threadToastData,
395 gitStatusForActions,
@@ -455,6 +448,54 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
448 threadToastData,
449 ]);
450
451 + const runDialogActionOnNewBranch = useCallback(() => {
452 + if (!isCommitDialogOpen) return;
453 + const action: GitStackedAction = "commit";
454 + const commitMessage = dialogCommitMessage.trim();
455 + const branchName = resolveAutoFeatureBranchName(branchList?.branches.map((branch) => branch.name) ?? []);
456 +
457 + setIsCommitDialogOpen(false);
458 + setDialogCommitMessage("");
459 +
460 + const checkoutPromise = createBranchAndCheckoutMutation.mutateAsync(branchName);
461 + toastManager.promise(checkoutPromise, {
462 + loading: { title: `Creating ${branchName}...`, data: threadToastData },
463 + success: () => ({
464 + title: `Checked out ${branchName}`,
465 + data: threadToastData,
466 + }),
467 + error: (error) => ({
468 + title: "Failed to checkout feature branch",
469 + description: error instanceof Error ? error.message : "An error occurred.",
470 + data: threadToastData,
471 + }),
472 + });
473 +
474 + void checkoutPromise
475 + .then(() => {
476 + const statusOverride = gitStatusForActions
477 + ? { ...gitStatusForActions, branch: branchName, pr: null }
478 + : null;
479 + return runGitActionWithToast({
480 + action,
481 + ...(commitMessage ? { commitMessage } : {}),
482 + skipDefaultBranchPrompt: true,
483 + statusOverride,
484 + isDefaultBranchOverride: false,
485 + });
486 + })
487 + .catch(() => undefined);
488 + }, [
489 + branchList?.branches,
490 + createBranchAndCheckoutMutation,
491 + dialogCommitMessage,
492 + gitStatusForActions,
493 + isCommitDialogOpen,
494 + runGitActionWithToast,
495 + setIsCommitDialogOpen,
496 + threadToastData,
497 + ]);
498 +
499 const runQuickAction = useCallback(() => {
500 if (quickAction.kind === "open_pr") {
501 void openExistingPr();
@@ -506,30 +547,24 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
547 void runGitActionWithToast({ action: "commit_push", forcePushOnlyProgress: true });
548 return;
549 }
509 - if (item.dialogAction) {
510 - setActiveDialogAction(item.dialogAction);
550 + if (item.dialogAction === "create_pr") {
551 + void runGitActionWithToast({ action: "commit_push_pr" });
552 + return;
553 }
554 + setIsCommitDialogOpen(true);
555 },
513 - [openExistingPr, runGitActionWithToast],
556 + [openExistingPr, runGitActionWithToast, setIsCommitDialogOpen],
557 );
558
559 const runDialogAction = useCallback(() => {
517 - if (!activeDialogAction) return;
518 - const action: GitStackedAction =
519 - activeDialogAction === "commit"
520 - ? "commit"
521 - : activeDialogAction === "push"
522 - ? "commit_push"
523 - : "commit_push_pr";
524 - const commitMessage = activeDialogAction === "commit" ? dialogCommitMessage.trim() : "";
525 - const forcePushOnlyProgress = activeDialogAction === "push";
526 - setActiveDialogAction(null);
560 + if (!isCommitDialogOpen) return;
561 + const commitMessage = dialogCommitMessage.trim();
562 + setIsCommitDialogOpen(false);
563 void runGitActionWithToast({
528 - action,
564 + action: "commit",
565 ...(commitMessage ? { commitMessage } : {}),
530 - ...(forcePushOnlyProgress ? { forcePushOnlyProgress } : {}),
566 });
532 - }, [activeDialogAction, dialogCommitMessage, runGitActionWithToast]);
567 + }, [dialogCommitMessage, isCommitDialogOpen, runGitActionWithToast, setIsCommitDialogOpen]);
568
569 const openChangedFileInEditor = useCallback(
570 (filePath: string) => {
@@ -685,68 +720,29 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
720 )}
721
722 <Dialog
688 - open={activeDialogAction !== null}
723 + open={isCommitDialogOpen}
724 onOpenChange={(open) => {
725 if (!open) {
691 - setActiveDialogAction(null);
726 + setIsCommitDialogOpen(false);
727 setDialogCommitMessage("");
728 }
729 }}
730 >
731 <DialogPopup>
732 <DialogHeader>
698 - <DialogTitle>{DIALOG_TITLE_BY_ACTION[activeDialogAction ?? "commit"]}</DialogTitle>
699 - <DialogDescription>
700 - {DIALOG_DESCRIPTION_BY_ACTION[activeDialogAction ?? "commit"]}
701 - </DialogDescription>
733 + <DialogTitle>{COMMIT_DIALOG_TITLE}</DialogTitle>
734 + <DialogDescription>{COMMIT_DIALOG_DESCRIPTION}</DialogDescription>
735 </DialogHeader>
736 <DialogPanel className="space-y-4">
737 <div className="space-y-3 rounded-lg border border-input bg-muted/40 p-3 text-xs">
738 <div className="grid grid-cols-[auto_1fr] items-center gap-x-2 gap-y-1">
739 <span className="text-muted-foreground">Branch</span>
707 - <span className="font-medium">
708 - {gitStatusForActions?.branch ?? "(detached HEAD)"}
740 + <span className="flex items-center justify-between gap-2">
741 + <span className="font-medium">{gitStatusForActions?.branch ?? "(detached HEAD)"}</span>
742 + {isDefaultBranch && (
743 + <span className="text-right text-warning text-xs">Warning: default branch</span>
744 + )}
745 </span>
710 - {activeDialogAction !== "commit" && (
711 - <>
712 - <span className="text-muted-foreground">Upstream</span>
713 - <span className="font-medium">
714 - {!gitStatusForActions || !gitStatusForActions.hasUpstream
715 - ? "No upstream configured"
716 - : gitStatusForActions.aheadCount === 0 &&
717 - gitStatusForActions.behindCount === 0
718 - ? "Up to date"
719 - : gitStatusForActions.aheadCount > 0 &&
720 - gitStatusForActions.behindCount > 0
721 - ? `Diverged (+${gitStatusForActions.aheadCount} / -${gitStatusForActions.behindCount})`
722 - : gitStatusForActions.aheadCount > 0
723 - ? `Ahead by ${gitStatusForActions.aheadCount}`
724 - : `Behind by ${gitStatusForActions.behindCount}`}
725 - </span>
726 - <span className="text-muted-foreground">Working tree</span>
727 - <span className="font-medium">
728 - {!gitStatusForActions || !gitStatusForActions.hasWorkingTreeChanges
729 - ? "Clean"
730 - : `${gitStatusForActions.workingTree.files.length} file(s)`}
731 - </span>
732 - <span className="text-muted-foreground">Diff</span>
733 - <span className="font-mono">
734 - {!gitStatusForActions || !gitStatusForActions.hasWorkingTreeChanges ? (
735 - "none"
736 - ) : (
737 - <>
738 - <span className="text-success">
739 - +{gitStatusForActions.workingTree.insertions}
740 - </span>
741 - <span className="text-muted-foreground"> / </span>
742 - <span className="text-destructive">
743 - -{gitStatusForActions.workingTree.deletions}
744 - </span>
745 - </>
746 - )}
747 - </span>
748 - </>
749 - )}
746 </div>
747 <div className="space-y-1">
748 <p className="text-muted-foreground">Files</p>
@@ -786,35 +782,32 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
782 )}
783 </div>
784 </div>
789 - {activeDialogAction === "commit" && (
790 - <div className="space-y-1">
791 - <p className="text-xs font-medium">Commit message (optional)</p>
792 - <Textarea
793 - value={dialogCommitMessage}
794 - onChange={(event) => setDialogCommitMessage(event.target.value)}
795 - placeholder="Leave empty to auto-generate"
796 - size="sm"
797 - />
798 - </div>
799 - )}
785 + <div className="space-y-1">
786 + <p className="text-xs font-medium">Commit message (optional)</p>
787 + <Textarea
788 + value={dialogCommitMessage}
789 + onChange={(event) => setDialogCommitMessage(event.target.value)}
790 + placeholder="Leave empty to auto-generate"
791 + size="sm"
792 + />
793 + </div>
794 </DialogPanel>
795 <DialogFooter>
796 <Button
797 variant="outline"
798 size="sm"
799 onClick={() => {
806 - setActiveDialogAction(null);
800 + setIsCommitDialogOpen(false);
801 setDialogCommitMessage("");
802 }}
803 >
804 Cancel
805 </Button>
806 + <Button variant="outline" size="sm" onClick={runDialogActionOnNewBranch}>
807 + Commit on new branch
808 + </Button>
809 <Button size="sm" onClick={runDialogAction}>
813 - {activeDialogAction === "commit"
814 - ? "Commit"
815 - : activeDialogAction === "push"
816 - ? "Push"
817 - : "Create PR"}
810 + Commit
811 </Button>
812 </DialogFooter>
813 </DialogPopup>