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 22, 05:45 UTC
fix(server): squash-merged branches no longer offer push & create PR (#28494)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 3, 2026 at 12:00 UTC
3040f91bb5cd320298712b337fa1415079259967
2 files changed
+279
-13
apps/server/src/git/GitManager.test.ts
+238
@@ -1848,6 +1848,244 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
1848
}),
1849
);
1850
1851
+ function squashMergeIntoRemoteMain(repoDir: string, branch: string) {
1852
+ return Effect.gen(function* () {
1853
+ yield* runGit(repoDir, ["push", "-u", "origin", "main"]);
1854
+ yield* runGit(repoDir, ["checkout", "-b", branch]);
1855
+ NodeFS.writeFileSync(NodePath.join(repoDir, "squash.txt"), "one\ntwo\n");
1856
+ yield* runGit(repoDir, ["add", "squash.txt"]);
1857
+ yield* runGit(repoDir, ["commit", "-m", "Feature work"]);
1858
+ yield* runGit(repoDir, ["push", "-u", "origin", branch]);
1859
+ // The host squash-merges: a new commit on main with the branch's tree, not the branch's commit.
1860
+ const squash = yield* runGit(repoDir, [
1861
+ "commit-tree",
1862
+ "HEAD^{tree}",
1863
+ "-p",
1864
+ "origin/main",
1865
+ "-m",
1866
+ "Feature work (#217)",
1867
+ ]);
1868
+ yield* runGit(repoDir, ["push", "origin", `${squash.stdout.trim()}:refs/heads/main`]);
1869
+ return (yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim();
1870
+ });
1871
+ }
1872
+
1873
+ const squashMergedPr = (branch: string, headSha: string): FakeChangeRequest => ({
1874
+ number: 217,
1875
+ title: "Feature work",
1876
+ url: "https://github.com/pingdotgg/t3code/pull/217",
1877
+ baseRefName: "main",
1878
+ headRefName: branch,
1879
+ headSha,
1880
+ state: "merged",
1881
+ mergedAt: "2026-04-02T15:00:00Z",
1882
+ updatedAt: "2026-04-02T15:00:00Z",
1883
+ });
1884
+
1885
+ it.effect("status reports nothing to ship after a squash merge deleted the remote branch", () =>
1886
+ Effect.gen(function* () {
1887
+ const repoDir = yield* makeTempDir("t3code-git-manager-");
1888
+ yield* initRepo(repoDir);
1889
+ const remoteDir = yield* createBareRemote();
1890
+ yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
1891
+ const branch = "feature/squash-deleted";
1892
+ const headSha = yield* squashMergeIntoRemoteMain(repoDir, branch);
1893
+ yield* runGit(repoDir, ["push", "origin", "--delete", branch]);
1894
+ yield* runGit(repoDir, ["fetch", "--prune", "origin"]);
1895
+
1896
+ const { manager } = yield* makeManager({
1897
+ providerScenario: { prListSequence: [[squashMergedPr(branch, headSha)]] },
1898
+ });
1899
+
1900
+ const status = yield* manager.status({ cwd: repoDir });
1901
+
1902
+ expect(status.pr?.state).toBe("merged");
1903
+ expect(status.hasUpstream).toBe(false);
1904
+ expect({
1905
+ aheadCount: status.aheadCount,
1906
+ aheadOfDefaultCount: status.aheadOfDefaultCount,
1907
+ }).toEqual({ aheadCount: 0, aheadOfDefaultCount: 0 });
1908
+ }),
1909
+ );
1910
+
1911
+ it.effect("status reports nothing to ship after a squash merge kept the remote branch", () =>
1912
+ Effect.gen(function* () {
1913
+ const repoDir = yield* makeTempDir("t3code-git-manager-");
1914
+ yield* initRepo(repoDir);
1915
+ const remoteDir = yield* createBareRemote();
1916
+ yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
1917
+ const branch = "feature/squash-kept";
1918
+ const headSha = yield* squashMergeIntoRemoteMain(repoDir, branch);
1919
+ yield* runGit(repoDir, ["fetch", "--prune", "origin"]);
1920
+
1921
+ const { manager } = yield* makeManager({
1922
+ providerScenario: { prListSequence: [[squashMergedPr(branch, headSha)]] },
1923
+ });
1924
+
1925
+ const status = yield* manager.status({ cwd: repoDir });
1926
+
1927
+ expect(status.pr?.state).toBe("merged");
1928
+ expect(status.hasUpstream).toBe(true);
1929
+ expect({
1930
+ aheadCount: status.aheadCount,
1931
+ aheadOfDefaultCount: status.aheadOfDefaultCount,
1932
+ }).toEqual({ aheadCount: 0, aheadOfDefaultCount: 0 });
1933
+ }),
1934
+ );
1935
+
1936
+ it.effect("status still reports work to ship for a commit added after a squash merge", () =>
1937
+ Effect.gen(function* () {
1938
+ const repoDir = yield* makeTempDir("t3code-git-manager-");
1939
+ yield* initRepo(repoDir);
1940
+ const remoteDir = yield* createBareRemote();
1941
+ yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
1942
+ const branch = "feature/squash-follow-up";
1943
+ const headSha = yield* squashMergeIntoRemoteMain(repoDir, branch);
1944
+ NodeFS.writeFileSync(NodePath.join(repoDir, "follow-up.txt"), "after merge\n");
1945
+ yield* runGit(repoDir, ["add", "follow-up.txt"]);
1946
+ yield* runGit(repoDir, ["commit", "-m", "Follow-up work"]);
1947
+ yield* runGit(repoDir, ["fetch", "--prune", "origin"]);
1948
+
1949
+ const { manager } = yield* makeManager({
1950
+ providerScenario: { prListSequence: [[squashMergedPr(branch, headSha)]] },
1951
+ });
1952
+
1953
+ const status = yield* manager.status({ cwd: repoDir });
1954
+
1955
+ expect(status.pr?.state).toBe("merged");
1956
+ expect(status.aheadCount).toBe(1);
1957
+ expect(status.aheadOfDefaultCount).toBe(2);
1958
+ }),
1959
+ );
1960
+
1961
+ it.effect("status still reports work against main after a merge into another base", () =>
1962
+ Effect.gen(function* () {
1963
+ const repoDir = yield* makeTempDir("t3code-git-manager-");
1964
+ yield* initRepo(repoDir);
1965
+ const initialSha = (yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim();
1966
+ const remoteDir = yield* createBareRemote();
1967
+ yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
1968
+ const branch = "feature/release-only";
1969
+ const headSha = yield* squashMergeIntoRemoteMain(repoDir, branch);
1970
+ // Move the merge to release and leave main without it.
1971
+ const squashSha = (yield* runGit(repoDir, ["rev-parse", "origin/main"])).stdout.trim();
1972
+ yield* runGit(repoDir, ["push", "origin", `${squashSha}:refs/heads/release`]);
1973
+ yield* runGit(repoDir, ["push", "--force", "origin", `${initialSha}:refs/heads/main`]);
1974
+ yield* runGit(repoDir, ["fetch", "origin"]);
1975
+
1976
+ const { manager } = yield* makeManager({
1977
+ providerScenario: {
1978
+ prListSequence: [[{ ...squashMergedPr(branch, headSha), baseRefName: "release" }]],
1979
+ },
1980
+ });
1981
+
1982
+ const status = yield* manager.status({ cwd: repoDir });
1983
+
1984
+ expect(status.pr?.state).toBe("merged");
1985
+ expect(status.aheadOfDefaultCount).toBe(1);
1986
+ }),
1987
+ );
1988
+
1989
+ it.effect("status keeps a squash-merged branch shipped when a later PR lookup fails", () =>
1990
+ Effect.gen(function* () {
1991
+ const repoDir = yield* makeTempDir("t3code-git-manager-");
1992
+ yield* initRepo(repoDir);
1993
+ const remoteDir = yield* createBareRemote();
1994
+ yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
1995
+ const branch = "feature/squash-lookup-fails";
1996
+ const headSha = yield* squashMergeIntoRemoteMain(repoDir, branch);
1997
+ yield* runGit(repoDir, ["push", "origin", "--delete", branch]);
1998
+ yield* runGit(repoDir, ["fetch", "--prune", "origin"]);
1999
+
2000
+ const { manager } = yield* makeManager({
2001
+ providerScenario: {
2002
+ prListSequence: [[squashMergedPr(branch, headSha)]],
2003
+ failWith: "Rate limited",
2004
+ failAfterCalls: 1,
2005
+ },
2006
+ });
2007
+
2008
+ const first = yield* manager.status({ cwd: repoDir });
2009
+ yield* manager.invalidateStatus(repoDir);
2010
+ const second = yield* manager.status({ cwd: repoDir });
2011
+
2012
+ expect(first.aheadOfDefaultCount).toBe(0);
2013
+ expect(second.pr?.state).toBe("merged");
2014
+ expect({
2015
+ aheadCount: second.aheadCount,
2016
+ aheadOfDefaultCount: second.aheadOfDefaultCount,
2017
+ }).toEqual({ aheadCount: 0, aheadOfDefaultCount: 0 });
2018
+ }),
2019
+ );
2020
+
2021
+ it.effect("status keeps real divergence for a squash-merged branch that tracks its base", () =>
2022
+ Effect.gen(function* () {
2023
+ const repoDir = yield* makeTempDir("t3code-git-manager-");
2024
+ yield* initRepo(repoDir);
2025
+ const remoteDir = yield* createBareRemote();
2026
+ yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
2027
+ const branch = "feature/squash-tracks-main";
2028
+ const headSha = yield* squashMergeIntoRemoteMain(repoDir, branch);
2029
+ yield* runGit(repoDir, ["fetch", "origin"]);
2030
+ yield* runGit(repoDir, ["branch", "--set-upstream-to", "origin/main"]);
2031
+
2032
+ const { manager } = yield* makeManager({
2033
+ providerScenario: { prListSequence: [[squashMergedPr(branch, headSha)]] },
2034
+ });
2035
+
2036
+ const status = yield* manager.status({ cwd: repoDir });
2037
+
2038
+ expect(status.pr?.state).toBe("merged");
2039
+ expect({ aheadCount: status.aheadCount, behindCount: status.behindCount }).toEqual({
2040
+ aheadCount: 1,
2041
+ behindCount: 1,
2042
+ });
2043
+ }),
2044
+ );
2045
+
2046
+ it.effect("status reports nothing to ship after a squash merge into a non-origin default", () =>
2047
+ Effect.gen(function* () {
2048
+ const repoDir = yield* makeTempDir("t3code-git-manager-");
2049
+ yield* initRepo(repoDir);
2050
+ yield* runGit(repoDir, ["branch", "-m", "develop"]);
2051
+ const remoteDir = yield* createBareRemote();
2052
+ yield* runGit(repoDir, ["remote", "add", "upstream", remoteDir]);
2053
+ yield* runGit(repoDir, ["push", "-u", "upstream", "develop"]);
2054
+ yield* runGit(repoDir, ["remote", "set-head", "upstream", "develop"]);
2055
+ const branch = "feature/squash-develop";
2056
+ yield* runGit(repoDir, ["checkout", "-b", branch]);
2057
+ NodeFS.writeFileSync(NodePath.join(repoDir, "squash.txt"), "one\ntwo\n");
2058
+ yield* runGit(repoDir, ["add", "squash.txt"]);
2059
+ yield* runGit(repoDir, ["commit", "-m", "Feature work"]);
2060
+ yield* runGit(repoDir, ["push", "-u", "upstream", branch]);
2061
+ const headSha = (yield* runGit(repoDir, ["rev-parse", "HEAD"])).stdout.trim();
2062
+ const squash = yield* runGit(repoDir, [
2063
+ "commit-tree",
2064
+ "HEAD^{tree}",
2065
+ "-p",
2066
+ "upstream/develop",
2067
+ "-m",
2068
+ "Feature work (#217)",
2069
+ ]);
2070
+ yield* runGit(repoDir, ["push", "upstream", `${squash.stdout.trim()}:refs/heads/develop`]);
2071
+ yield* runGit(repoDir, ["fetch", "upstream"]);
2072
+
2073
+ const { manager } = yield* makeManager({
2074
+ providerScenario: {
2075
+ prListSequence: [[{ ...squashMergedPr(branch, headSha), baseRefName: "develop" }]],
2076
+ },
2077
+ });
2078
+
2079
+ const status = yield* manager.status({ cwd: repoDir });
2080
+
2081
+ expect(status.pr?.state).toBe("merged");
2082
+ expect({
2083
+ aheadCount: status.aheadCount,
2084
+ aheadOfDefaultCount: status.aheadOfDefaultCount,
2085
+ }).toEqual({ aheadCount: 0, aheadOfDefaultCount: 0 });
2086
+ }),
2087
+ );
2088
+
2089
it.each([
2090
[
2091
"https://github.example.com/team/repository/pull/42?tab=files",
apps/server/src/git/GitManager.ts
+41
-13
@@ -1259,6 +1259,7 @@ export const make = Effect.gen(function* () {
1259
const getPrLookup = (key: string) => detachStackFrame(Cache.get(prLookupCache, key));
1260
interface LastKnownPr {
1261
readonly pr: ReturnType<typeof toStatusPr> | null;
1262
+ readonly headSha: string | null;
1263
readonly upstreamRef: string | null;
1264
readonly headBranch: string;
1265
readonly remoteName: string | null;
@@ -1280,7 +1281,7 @@ export const make = Effect.gen(function* () {
1281
const resolveLastKnownPr = (
1282
branchKey: string,
1283
current: Pick<LastKnownPr, "upstreamRef" | "headBranch" | "remoteName" | "headRemoteUrlKey">,
1283
- ): ReturnType<typeof toStatusPr> | null => {
1284
+ ): LastKnownPr | null => {
1285
const lastKnown = lastKnownPrByBranchKey.get(branchKey);
1286
if (!lastKnown) return null;
1287
if (lastKnown.headBranch !== current.headBranch) {
@@ -1289,7 +1290,7 @@ export const make = Effect.gen(function* () {
1290
1291
// Config read failures become null; require both remote URLs before treating a mismatch as real.
1292
if (lastKnown.headRemoteUrlKey !== null && current.headRemoteUrlKey !== null) {
1292
- return lastKnown.headRemoteUrlKey === current.headRemoteUrlKey ? lastKnown.pr : null;
1293
+ return lastKnown.headRemoteUrlKey === current.headRemoteUrlKey ? lastKnown : null;
1294
}
1295
1296
if (
@@ -1298,9 +1299,9 @@ export const make = Effect.gen(function* () {
1299
lastKnown.remoteName !== null &&
1300
current.remoteName !== null
1301
) {
1301
- return lastKnown.remoteName === current.remoteName ? lastKnown.pr : null;
1302
+ return lastKnown.remoteName === current.remoteName ? lastKnown : null;
1303
}
1303
- return lastKnown.pr;
1304
+ return lastKnown;
1305
};
1306
const lookupStatusPr = Effect.fn("lookupStatusPr")(function* (
1307
cwd: string,
@@ -1325,17 +1326,18 @@ export const make = Effect.gen(function* () {
1326
}
1327
return yield* getPrLookup(cacheKey).pipe(
1328
Effect.map(({ latest, headContext }) => {
1328
- if (!latest) return { pr: null, headContext };
1329
+ if (!latest) return { pr: null, headSha: null, headContext };
1330
// Merged/closed matches are usually reverse-merge history, not the thread's PR context.
1331
if (details.isDefaultBranch && latest.state !== "open") {
1331
- return { pr: null, headContext };
1332
+ return { pr: null, headSha: null, headContext };
1333
}
1333
- return { pr: toStatusPr(latest), headContext };
1334
+ return { pr: toStatusPr(latest), headSha: latest.headSha ?? null, headContext };
1335
}),
1335
- Effect.tap(({ pr, headContext }) =>
1336
+ Effect.tap(({ pr, headSha, headContext }) =>
1337
Effect.sync(() =>
1338
rememberLastKnownPr(branchKey, {
1339
pr,
1340
+ headSha,
1341
upstreamRef: details.upstreamRef,
1342
headBranch: headContext.headBranch,
1343
remoteName: headContext.remoteName,
@@ -1343,7 +1345,7 @@ export const make = Effect.gen(function* () {
1345
}),
1346
),
1347
),
1346
- Effect.map(({ pr }) => pr),
1348
+ Effect.map(({ pr, headSha }) => ({ pr, headSha })),
1349
Effect.catch((error) => {
1350
const fallback = lastKnownPrByBranchKey.get(branchKey)?.pr
1351
? resolveLookupHeadContext(cwd, details).pipe(
@@ -1375,6 +1377,10 @@ export const make = Effect.gen(function* () {
1377
: {}),
1378
}),
1379
Effect.andThen(fallback),
1380
+ Effect.map((lastKnown) => ({
1381
+ pr: lastKnown?.pr ?? null,
1382
+ headSha: lastKnown?.headSha ?? null,
1383
+ })),
1384
);
1385
}),
1386
);
@@ -1390,7 +1396,7 @@ export const make = Effect.gen(function* () {
1396
return null;
1397
}
1398
1393
- const pr =
1399
+ const { pr, headSha } =
1400
details.branch !== null
1401
? yield* lookupStatusPr(
1402
cwd,
@@ -1402,13 +1408,35 @@ export const make = Effect.gen(function* () {
1408
},
1409
options?.refreshMissingPullRequest,
1410
)
1405
- : null;
1411
+ : { pr: null, headSha: null };
1412
+ // Squash and rebase merges land new commits, so HEAD never becomes reachable from the base.
1413
+ const shippedByMergedPr =
1414
+ pr?.state === "merged" &&
1415
+ headSha !== null &&
1416
+ (yield* Effect.gen(function* () {
1417
+ const defaultBranch =
1418
+ details.defaultBranch ??
1419
+ (yield* gitCore.resolvePrimaryRemoteName(cwd).pipe(
1420
+ Effect.flatMap((remoteName) => gitCore.resolveDefaultBranchName(cwd, remoteName)),
1421
+ Effect.orElseSucceed(() => null),
1422
+ ));
1423
+ const mergedIntoDefault =
1424
+ defaultBranch === null
1425
+ ? pr.baseRef === "main" || pr.baseRef === "master"
1426
+ : pr.baseRef === defaultBranch;
1427
+ if (!mergedIntoDefault) return false;
1428
+ return yield* gitCore.resolveCommit({ cwd, revision: "HEAD" }).pipe(
1429
+ Effect.map(({ commitSha }) => commitSha === headSha),
1430
+ Effect.orElseSucceed(() => false),
1431
+ );
1432
+ }));
1433
1434
return {
1435
hasUpstream: details.hasUpstream,
1409
- aheadCount: details.aheadCount,
1436
+ // A real upstream delta stays; only the no-upstream fallback counts against the base.
1437
+ aheadCount: shippedByMergedPr && !details.hasUpstream ? 0 : details.aheadCount,
1438
behindCount: details.behindCount,
1411
- aheadOfDefaultCount: details.aheadOfDefaultCount,
1439
+ aheadOfDefaultCount: shippedByMergedPr ? 0 : details.aheadOfDefaultCount,
1440
pr,
1441
} satisfies VcsStatusRemoteResult;
1442
});