Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/web/src/components/GitActionsControl.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { resolveAutoFeatureBranchName } from "@t3tools/shared/git";
import { assert, describe, it } from "vite-plus/test";
import {
buildMenuItems,
type DefaultBranchConfirmableAction,
requiresDefaultBranchConfirmation,
resolveChangesTotals,
resolveDefaultBranchActionDialogCopy,
resolveFeatureBranchUnavailableReason,
resolveLiveThreadBranchUpdate,
resolveQuickAction,
} from "./GitActionsControl.logic";
Expand Down Expand Up @@ -93,6 +95,16 @@ describe("when: on default ref without open PR", () => {
disabled: false,
});
});

it("offers a feature branch only to actions that commit the changes", () => {
const reason = (action: DefaultBranchConfirmableAction, hasWorkingTreeChanges: boolean) =>
resolveFeatureBranchUnavailableReason({ action, branchName: "main", hasWorkingTreeChanges });
assert.isNull(reason("commit_push", true));
assert.isNull(reason("commit_push_pr", true));
assert.isNotNull(reason("commit_push", false));
assert.isNotNull(reason("push", true));
assert.isNotNull(reason("create_pr", true));
});
});

describe("when: local changes are behind upstream", () => {
Expand Down
12 changes: 9 additions & 3 deletions apps/web/src/components/GitActionsControl.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,19 @@ export function resolveDefaultBranchActionDialogCopy(input: {
};
}

/** Clean trees cannot create feature branches because the server derives names from uncommitted changes. */
/** The server names a feature branch from the commit it makes, so the action must commit changes. */
export function resolveFeatureBranchUnavailableReason(input: {
action: DefaultBranchConfirmableAction;
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}.`;
if (!input.hasWorkingTreeChanges) {
return `There are no changes to commit, so a feature branch can't be named. Create a branch yourself or continue on ${input.branchName}.`;
}
if (input.action === "push" || input.action === "create_pr") {
return `This action doesn't commit your changes, so a feature branch can't be named. Create a branch yourself or continue on ${input.branchName}.`;
}
return null;
}

export function resolveThreadBranchUpdate(
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/GitActionsControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,7 @@ export default function GitActionsControl({
// Keep enabled until live status loads; the server rejects stale requests.
const featureBranchUnavailableReason = pendingDefaultBranchAction
? resolveFeatureBranchUnavailableReason({
action: pendingDefaultBranchAction.action,
branchName: pendingDefaultBranchAction.branchName,
hasWorkingTreeChanges: gitStatus?.hasWorkingTreeChanges ?? true,
})
Expand Down
Loading