Skip to content

Commit e9dd8a6

Browse files
only21milcodexclaude
authored
fix(clients): offer Commit when the branch is behind upstream (#24117)
Co-authored-by: GPT-6.1 Sol <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent c84acfa commit e9dd8a6

4 files changed

Lines changed: 78 additions & 2 deletions

File tree

‎apps/web/src/components/GitActionsControl.logic.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,36 @@ describe("when: on default ref without open PR", () => {
9494
});
9595
});
9696

97+
describe("when: local changes are behind upstream", () => {
98+
it("keeps the commit action available without pushing, with or without an open PR", () => {
99+
const behind = status({ hasWorkingTreeChanges: true, behindCount: 2 });
100+
const commit = {
101+
label: "Commit",
102+
disabled: false,
103+
kind: "run_action",
104+
action: "commit",
105+
} as const;
106+
assert.deepEqual(resolveQuickAction(behind, false), commit);
107+
assert.deepEqual(
108+
resolveQuickAction(
109+
{
110+
...behind,
111+
pr: {
112+
number: 13,
113+
title: "Open PR",
114+
url: "https://example.com/pr/13",
115+
baseRef: "main",
116+
headRef: "feature/test",
117+
state: "open",
118+
},
119+
},
120+
false,
121+
),
122+
commit,
123+
);
124+
});
125+
});
126+
97127
describe("when: ref has no upstream configured", () => {
98128
it("resolveQuickAction runs push and create PR when no upstream and commits are ahead", () => {
99129
const quick = resolveQuickAction(

‎apps/web/src/components/GitActionsControl.logic.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export function resolveQuickAction(
212212
}
213213

214214
if (hasChanges) {
215-
if (!gitStatus.hasUpstream && !hasPrimaryRemote) {
215+
if (isBehind || (!gitStatus.hasUpstream && !hasPrimaryRemote)) {
216216
return { label: "Commit", disabled: false, kind: "run_action", action: "commit" };
217217
}
218218
if (hasOpenPr || isDefaultRef) {

‎packages/client-runtime/src/state/gitActions.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export function resolveQuickAction(
152152
}
153153

154154
if (hasChanges) {
155-
if (!gitStatus.hasUpstream && !hasOriginRemote) {
155+
if (isBehind || (!gitStatus.hasUpstream && !hasOriginRemote)) {
156156
return { label: "Commit", disabled: false, kind: "run_action", action: "commit" };
157157
}
158158
if (hasOpenPr || isDefaultBranch) {

‎packages/client-runtime/src/state/vcs.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
WS_METHODS,
66
VcsProcessExitError,
77
type VcsListRefsResult,
8+
type VcsStatusResult,
89
} from "@t3tools/contracts";
910
import { describe, expect, it } from "@effect/vitest";
1011
import * as Deferred from "effect/Deferred";
@@ -37,6 +38,7 @@ import {
3738
commitVcsRefsRefresh,
3839
createVcsEnvironmentAtoms,
3940
makeCachedVcsRefsChanges,
41+
resolveQuickAction,
4042
} from "./vcs.ts";
4143
import {
4244
invalidateCachedVcsRefs,
@@ -618,3 +620,47 @@ const grantedSessions = Atom.family((_id: EnvironmentId) =>
618620
}),
619621
),
620622
);
623+
624+
function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
625+
return {
626+
isRepo: true,
627+
hasPrimaryRemote: true,
628+
isDefaultRef: false,
629+
refName: "feature/test",
630+
hasWorkingTreeChanges: false,
631+
workingTree: {
632+
files: [],
633+
insertions: 0,
634+
deletions: 0,
635+
},
636+
hasUpstream: true,
637+
aheadCount: 0,
638+
behindCount: 0,
639+
pr: null,
640+
...overrides,
641+
};
642+
}
643+
644+
describe("resolveQuickAction", () => {
645+
it("commits local changes without pushing when the branch is behind upstream", () => {
646+
const behind = status({ hasWorkingTreeChanges: true, behindCount: 2 });
647+
const commit = { label: "Commit", disabled: false, kind: "run_action", action: "commit" };
648+
expect(resolveQuickAction(behind, false)).toEqual(commit);
649+
expect(
650+
resolveQuickAction(
651+
{
652+
...behind,
653+
pr: {
654+
number: 13,
655+
title: "Open PR",
656+
url: "https://example.com/pr/13",
657+
baseRef: "main",
658+
headRef: "feature/test",
659+
state: "open",
660+
},
661+
},
662+
false,
663+
),
664+
).toEqual(commit);
665+
});
666+
});

0 commit comments

Comments
 (0)