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(github): Rebase stack no longer conflicts after a lower layer is squash-merged (#29919)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alex Southwell committed
Nov 3, 2026 at 18:18 UTC
30724e2e9ae1c2f5da495b590e22e41e425b8db5
4 files changed
+70
-4
packages/source-control-github/src/server/githubStackActions.test.ts
+1
-1
@@ -341,7 +341,7 @@ it.effect("rebases the open layers bottom to top in a scratch clone, each onto t
341
expect(api.calls.some(isMutation)).toBe(false);
342
const rebases = gitCalls.filter((args) => args[0] === "rebase");
343
expect(rebases).toEqual([
344
- ["rebase", "--quiet", "--onto", "origin/main", "new-sha"],
344
+ ["rebase", "--quiet", "--onto", "origin/main", "aaa"],
345
["rebase", "--quiet", "--onto", "new-sha", "bbb"],
346
]);
347
expect(gitCalls.filter((args) => args[0] === "push")).toEqual([
packages/source-control-github/src/server/githubStackActions.ts
+2
@@ -201,6 +201,7 @@ export const runGitHubStackAction = Effect.fn("runGitHubStackAction")(function*
201
})
202
)
203
return yield* new GitHubStackPermissionError({ ...identity });
204
+ const mergedHeadSha = stack.layers[stack.layers.indexOf(open[0]!) - 1]?.headSha;
205
// GitHub has no stack-rebase API; per-PR updates replay lower layers' old commits.
206
yield* cascadeRebaseStack({
207
host: input.host,
@@ -211,6 +212,7 @@ export const runGitHubStackAction = Effect.fn("runGitHubStackAction")(function*
212
headBranch: layer.headBranch,
213
headSha: layer.headSha!,
214
})),
215
+ ...(mergedHeadSha === undefined ? {} : { mergedHeadSha }),
216
}).pipe(
217
Effect.mapError((cause) =>
218
cause._tag === "GitHubStackRebaseConflictError" ||
packages/source-control-github/src/server/githubStackRebase.test.ts
+53
@@ -92,6 +92,59 @@ it.layer(layer)("cascadeRebaseStack", (it) => {
92
}).pipe(Effect.scoped),
93
);
94
95
+ it.effect("drops a squash-merged lower layer's commits from the layer above it", () =>
96
+ Effect.gen(function* () {
97
+ const repo = yield* setup;
98
+ const fs = yield* FileSystem.FileSystem;
99
+ const { process } = yield* SourceControlHost.SourceControlHost;
100
+ const scratch = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cascade-squash-" });
101
+ const run = (...args: string[]) =>
102
+ process
103
+ .run({
104
+ operation: "test",
105
+ command: "git",
106
+ args,
107
+ cwd: scratch,
108
+ env: {
109
+ GIT_AUTHOR_NAME: "t",
110
+ GIT_AUTHOR_EMAIL: "t@t",
111
+ GIT_COMMITTER_NAME: "t",
112
+ GIT_COMMITTER_EMAIL: "t@t",
113
+ },
114
+ })
115
+ .pipe(Effect.map((out) => out.stdout.trim()));
116
+ const write = (text: string) => fs.writeFileString(`${scratch}/index.ts`, text);
117
+ yield* run("clone", "--quiet", repo.remote, ".");
118
+ yield* run("switch", "--quiet", "-c", "feat/two-steps");
119
+ yield* write("export const answer = 40;\n");
120
+ yield* run("commit", "--quiet", "-am", "A1");
121
+ yield* write("export const answer = 42;\n");
122
+ yield* run("commit", "--quiet", "-am", "A2");
123
+ const mergedHeadSha = yield* run("rev-parse", "HEAD");
124
+ yield* run("switch", "--quiet", "-c", "feat/on-top");
125
+ yield* write("/** The answer. */\nexport const answer = 42;\n");
126
+ yield* run("commit", "--quiet", "-am", "B");
127
+ const headSha = yield* run("rev-parse", "HEAD");
128
+ yield* run("switch", "--quiet", "main");
129
+ yield* run("merge", "--quiet", "--squash", "feat/two-steps");
130
+ yield* run("commit", "--quiet", "-m", "A (#1)");
131
+ yield* run("push", "--quiet", "origin", "main", "feat/on-top");
132
+
133
+ const completed = yield* cascadeRebaseStack({
134
+ host: "github.com",
135
+ repository: "acme/web",
136
+ base: "main",
137
+ layers: [{ number: 2, headBranch: "feat/on-top", headSha }],
138
+ mergedHeadSha,
139
+ remote: repo.remote,
140
+ });
141
+ assert.strictEqual(completed, 1);
142
+ const top = yield* repo.head("feat/on-top");
143
+ expect(yield* repo.git("rev-parse", `${top}~1`)).toBe(yield* repo.head("main"));
144
+ expect(yield* repo.git("log", "--format=%s", `main..${top}`)).toBe("B");
145
+ }).pipe(Effect.scoped),
146
+ );
147
+
148
it.effect("refuses to overwrite a layer pushed after it was reviewed", () =>
149
Effect.gen(function* () {
150
const repo = yield* setup;
packages/source-control-github/src/server/githubStackRebase.ts
+14
-3
@@ -40,6 +40,8 @@ export const cascadeRebaseStack = Effect.fn("cascadeRebaseStack")(function* (inp
40
readonly repository: string;
41
readonly base: string;
42
readonly layers: ReadonlyArray<CascadeLayer>;
43
+ /** Last head of the merged layer directly below the bottom open layer. */
44
+ readonly mergedHeadSha?: string;
45
readonly remote?: string;
46
}) {
47
const appAccess = yield* GitHubAppAccess.GitHubAppAccess;
@@ -103,13 +105,22 @@ export const cascadeRebaseStack = Effect.fn("cascadeRebaseStack")(function* (inp
105
106
let parentOld = `origin/${input.base}`;
107
let parentNew = `origin/${input.base}`;
108
+ // A squash or rebase merge leaves the merged layer's commits outside the base's history.
109
+ const mergedParent =
110
+ input.mergedHeadSha !== undefined &&
111
+ (yield* git(["merge-base", "--is-ancestor", input.mergedHeadSha, first.headSha], true).pipe(
112
+ Effect.mapError(failed("reading the fork point", first.number, 0)),
113
+ )).exitCode === 0
114
+ ? input.mergedHeadSha
115
+ : undefined;
116
for (const [index, layer] of input.layers.entries()) {
107
- // Exclude old parents: the base fork point for the bottom, the reviewed lower head above it.
117
+ // Exclude old parents: the merged layer or fork point for the bottom, the reviewed head above.
118
const upstream =
119
index === 0
110
- ? (yield* git(["merge-base", parentOld, layer.headSha]).pipe(
120
+ ? (mergedParent ??
121
+ (yield* git(["merge-base", parentOld, layer.headSha]).pipe(
122
Effect.mapError(failed("reading the fork point", layer.number, index)),
112
- )).stdout.trim()
123
+ )).stdout.trim())
124
: parentOld;
125
yield* git(["checkout", "--quiet", "--detach", layer.headSha]).pipe(
126
Effect.mapError(failed("checking out", layer.number, index)),