Skip to content
TypeScript

fix(web): the default-branch dialog no longer offers a feature branch it cannot create (#18716)

Igor Makowski7241e7ee5098
diff --git a/apps/web/src/components/GitActionsControl.logic.test.ts b/apps/web/src/components/GitActionsControl.logic.test.ts
index 12aee26c757..35f1f565aeb 100644
--- a/apps/web/src/components/GitActionsControl.logic.test.ts
+++ b/apps/web/src/components/GitActionsControl.logic.test.ts
@@ -8,6 +8,7 @@ import {
requiresDefaultBranchConfirmation,
resolveAutoFeatureBranchName,
resolveDefaultBranchActionDialogCopy,
+ resolveFeatureBranchUnavailableReason,
resolveGitActionProgressPresentation,
resolveGitActionResultToastTiming,
resolveLiveThreadBranchUpdate,
@@ -1025,6 +1026,21 @@ describe("resolveDefaultBranchActionDialogCopy", () => {
});
});
+describe("resolveFeatureBranchUnavailableReason", () => {
+ it("blocks the feature branch when there is nothing to commit", () => {
+ assert.equal(
+ resolveFeatureBranchUnavailableReason({ branchName: "main", hasWorkingTreeChanges: false }),
+ "There are no changes to commit, so a feature branch can't be named. Create a branch yourself or continue on main.",
+ );
+ });
+
+ it("allows the feature branch when there are changes to commit", () => {
+ assert.isNull(
+ resolveFeatureBranchUnavailableReason({ branchName: "main", hasWorkingTreeChanges: true }),
+ );
+ });
+});
+
describe("buildGitActionProgressStages", () => {
it("shows only push progress for explicit push actions", () => {
const stages = buildGitActionProgressStages({
diff --git a/apps/web/src/components/GitActionsControl.logic.ts b/apps/web/src/components/GitActionsControl.logic.ts
index 187a8317bf9..0a794b3f474 100644
--- a/apps/web/src/components/GitActionsControl.logic.ts
+++ b/apps/web/src/components/GitActionsControl.logic.ts
@@ -428,6 +428,18 @@ export function resolveDefaultBranchActionDialogCopy(input: {
};
}
+/**
+ * Why the default-ref dialog cannot check out a feature branch, or null when it can.
+ * The server names that branch from the uncommitted changes, so a clean tree cannot use it.
+ */
+export function resolveFeatureBranchUnavailableReason(input: {
+ branchName: string;
+ hasWorkingTreeChanges: boolean;
+}): string | null {
+ if (input.hasWorkingTreeChanges) return null;
+ return `There are no changes to commit, so a feature branch can't be named. Create a branch yourself or continue on ${input.branchName}.`;
+}
+
export function resolveThreadBranchUpdate(
result: GitRunStackedActionResult,
): { branch: string } | null {
diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsx
index ffea29c9bf6..aaef0fe45f6 100644
--- a/apps/web/src/components/GitActionsControl.tsx
+++ b/apps/web/src/components/GitActionsControl.tsx
@@ -52,6 +52,7 @@ import {
type DefaultBranchConfirmableAction,
requiresDefaultBranchConfirmation,
resolveDefaultBranchActionDialogCopy,
+ resolveFeatureBranchUnavailableReason,
resolveGitActionProgressPresentation,
resolveGitActionResultToastTiming,
resolveLiveThreadBranchUpdate,
@@ -1155,6 +1156,15 @@ export default function GitActionsControl({
terminology: changeRequestTerminology,
})
: null;
+ // Follows the live status so the button tracks the tree while the dialog is open. Until the
+ // status loads, keep the option enabled: the server stays the authority and rejects a stale
+ // request with its own error.
+ const featureBranchUnavailableReason = pendingDefaultBranchAction
+ ? resolveFeatureBranchUnavailableReason({
+ branchName: pendingDefaultBranchAction.branchName,
+ hasWorkingTreeChanges: gitStatus?.hasWorkingTreeChanges ?? true,
+ })
+ : null;
useEffect(() => {
if (gitCwd === null) {
@@ -2039,6 +2049,9 @@ export default function GitActionsControl({
{pendingDefaultBranchActionCopy?.title ?? "Run action on default branch?"}
</DialogTitle>
<DialogDescription>{pendingDefaultBranchActionCopy?.description}</DialogDescription>
+ {featureBranchUnavailableReason && (
+ <p className="text-xs text-muted-foreground">{featureBranchUnavailableReason}</p>
+ )}
</DialogHeader>
<DialogFooter variant="bare" className="sm:flex-wrap sm:items-center">
<Button
@@ -2062,7 +2075,7 @@ export default function GitActionsControl({
className="w-full max-w-full sm:w-auto"
size="sm-multiline"
onClick={checkoutFeatureBranchAndContinuePendingAction}
- disabled={!canChangeThreadBranch}
+ disabled={!canChangeThreadBranch || featureBranchUnavailableReason !== null}
>
Check out feature branch & continue
</Button>