Skip to content
TypeScript

fix(clients): offer Commit when the branch is behind upstream (#24117)

Victor Vogele9dd8a68eeb8
diff --git a/apps/web/src/components/GitActionsControl.logic.test.ts b/apps/web/src/components/GitActionsControl.logic.test.ts
index 89ae4413677..5c202fccf5a 100644
--- a/apps/web/src/components/GitActionsControl.logic.test.ts
+++ b/apps/web/src/components/GitActionsControl.logic.test.ts
@@ -94,6 +94,36 @@ describe("when: on default ref without open PR", () => {
});
});
+describe("when: local changes are behind upstream", () => {
+ it("keeps the commit action available without pushing, with or without an open PR", () => {
+ const behind = status({ hasWorkingTreeChanges: true, behindCount: 2 });
+ const commit = {
+ label: "Commit",
+ disabled: false,
+ kind: "run_action",
+ action: "commit",
+ } as const;
+ assert.deepEqual(resolveQuickAction(behind, false), commit);
+ assert.deepEqual(
+ resolveQuickAction(
+ {
+ ...behind,
+ pr: {
+ number: 13,
+ title: "Open PR",
+ url: "https://example.com/pr/13",
+ baseRef: "main",
+ headRef: "feature/test",
+ state: "open",
+ },
+ },
+ false,
+ ),
+ commit,
+ );
+ });
+});
+
describe("when: ref has no upstream configured", () => {
it("resolveQuickAction runs push and create PR when no upstream and commits are ahead", () => {
const quick = resolveQuickAction(
diff --git a/apps/web/src/components/GitActionsControl.logic.ts b/apps/web/src/components/GitActionsControl.logic.ts
index 65123285a78..98a55c3577e 100644
--- a/apps/web/src/components/GitActionsControl.logic.ts
+++ b/apps/web/src/components/GitActionsControl.logic.ts
@@ -212,7 +212,7 @@ export function resolveQuickAction(
}
if (hasChanges) {
- if (!gitStatus.hasUpstream && !hasPrimaryRemote) {
+ if (isBehind || (!gitStatus.hasUpstream && !hasPrimaryRemote)) {
return { label: "Commit", disabled: false, kind: "run_action", action: "commit" };
}
if (hasOpenPr || isDefaultRef) {
diff --git a/packages/client-runtime/src/state/gitActions.ts b/packages/client-runtime/src/state/gitActions.ts
index cecd97c1d12..fe5a2b77c4e 100644
--- a/packages/client-runtime/src/state/gitActions.ts
+++ b/packages/client-runtime/src/state/gitActions.ts
@@ -152,7 +152,7 @@ export function resolveQuickAction(
}
if (hasChanges) {
- if (!gitStatus.hasUpstream && !hasOriginRemote) {
+ if (isBehind || (!gitStatus.hasUpstream && !hasOriginRemote)) {
return { label: "Commit", disabled: false, kind: "run_action", action: "commit" };
}
if (hasOpenPr || isDefaultBranch) {
diff --git a/packages/client-runtime/src/state/vcs.test.ts b/packages/client-runtime/src/state/vcs.test.ts
index 0a8b6f9cb6b..b5cdf7004fd 100644
--- a/packages/client-runtime/src/state/vcs.test.ts
+++ b/packages/client-runtime/src/state/vcs.test.ts
@@ -5,6 +5,7 @@ import {
WS_METHODS,
VcsProcessExitError,
type VcsListRefsResult,
+ type VcsStatusResult,
} from "@t3tools/contracts";
import { describe, expect, it } from "@effect/vitest";
import * as Deferred from "effect/Deferred";
@@ -37,6 +38,7 @@ import {
commitVcsRefsRefresh,
createVcsEnvironmentAtoms,
makeCachedVcsRefsChanges,
+ resolveQuickAction,
} from "./vcs.ts";
import {
invalidateCachedVcsRefs,
@@ -618,3 +620,47 @@ const grantedSessions = Atom.family((_id: EnvironmentId) =>
}),
),
);
+
+function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
+ return {
+ isRepo: true,
+ hasPrimaryRemote: true,
+ isDefaultRef: false,
+ refName: "feature/test",
+ hasWorkingTreeChanges: false,
+ workingTree: {
+ files: [],
+ insertions: 0,
+ deletions: 0,
+ },
+ hasUpstream: true,
+ aheadCount: 0,
+ behindCount: 0,
+ pr: null,
+ ...overrides,
+ };
+}
+
+describe("resolveQuickAction", () => {
+ it("commits local changes without pushing when the branch is behind upstream", () => {
+ const behind = status({ hasWorkingTreeChanges: true, behindCount: 2 });
+ const commit = { label: "Commit", disabled: false, kind: "run_action", action: "commit" };
+ expect(resolveQuickAction(behind, false)).toEqual(commit);
+ expect(
+ resolveQuickAction(
+ {
+ ...behind,
+ pr: {
+ number: 13,
+ title: "Open PR",
+ url: "https://example.com/pr/13",
+ baseRef: "main",
+ headRef: "feature/test",
+ state: "open",
+ },
+ },
+ false,
+ ),
+ ).toEqual(commit);
+ });
+});