authorgravatar for saiansh2525@gmail.comYash Singh <saiansh2525@gmail.com> 2026-09-22 19:40:40-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-22 19:40:40-05:00
logf22331240ed1a97fae560e314bffb75fe39db8ca
treef6b8bb582f8ff130b223703aaee373e3a6bb3107
parent5821b778fd29e9c5b6945f4e7150f92d19a0a3da
signature Signed by PGP key B5690EEEBB952194

fix(server): generate PR diffs from branch changes (#13170)


2 files changed, 22 insertions(+), 5 deletions(-)

apps/server/src/git/GitManager.test.ts+16-1
......@@ -4071,7 +4071,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
40714071 }),
40724072 );
40734073
4074 it.effect("generates PR content against the remote base when the local base is stale", () =>
4074 it.effect("generates PR content from branch changes when the remote base advances", () =>
40754075 Effect.gen(function* () {
40764076 const repoDir = yield* makeTempDir("t3code-git-manager-");
40774077 yield* initRepo(repoDir);
......@@ -4103,7 +4103,15 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
41034103 yield* runGit(repoDir, ["push", "-u", "origin", "feature/remote-base"]);
41044104 yield* runGit(repoDir, ["config", "branch.feature/remote-base.gh-merge-base", "main"]);
41054105
4106 NodeFS.writeFileSync(NodePath.join(peerDir, "later-main.txt"), "unrelated\n");
4107 yield* runGit(peerDir, ["add", "later-main.txt"]);
4108 yield* runGit(peerDir, ["commit", "-m", "Later main commit"]);
4109 yield* runGit(peerDir, ["push", "origin", "main"]);
4110 yield* runGit(repoDir, ["fetch", "origin"]);
4111
41064112 let generatedCommitSummary = "";
4113 let generatedDiffSummary = "";
4114 let generatedDiffPatch = "";
41074115 const { manager } = yield* makeManager({
41084116 ghScenario: {
41094117 prListSequence: ["[]", "[]"],
......@@ -4111,6 +4119,8 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
41114119 textGeneration: {
41124120 generatePrContent: (input) => {
41134121 generatedCommitSummary = input.commitSummary;
4122 generatedDiffSummary = input.diffSummary;
4123 generatedDiffPatch = input.diffPatch;
41144124 return Effect.succeed({ title: "Feature PR", body: "Feature body" });
41154125 },
41164126 },
......@@ -4124,6 +4134,11 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
41244134 expect(result.pr.status).toBe("created");
41254135 expect(generatedCommitSummary).toContain("Feature commit");
41264136 expect(generatedCommitSummary).not.toContain("Remote base commit");
4137 expect(generatedCommitSummary).not.toContain("Later main commit");
4138 expect(generatedDiffSummary).toContain("feature.txt");
4139 expect(generatedDiffSummary).not.toContain("later-main.txt");
4140 expect(generatedDiffPatch).toContain("feature.txt");
4141 expect(generatedDiffPatch).not.toContain("later-main.txt");
41274142 }),
41284143 );
41294144
apps/server/src/vcs/GitVcsDriverCore.ts+6-4
......@@ -2285,13 +2285,15 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
22852285 const readRangeContext: GitVcsDriver.GitVcsDriver["Service"]["readRangeContext"] = Effect.fn(
22862286 "readRangeContext",
22872287 )(function* (cwd, baseRef) {
2288 const range = `${baseRef}..HEAD`;
2288 const commitRange = `${baseRef}..HEAD`;
2289 // PR diffs start at the common ancestor when the base branch has advanced.
2290 const diffRange = `${baseRef}...HEAD`;
22892291 const [commitSummary, diffSummary, diffPatch] = yield* Effect.all(
22902292 [
22912293 runGitStdoutWithOptions(
22922294 "GitVcsDriver.readRangeContext.log",
22932295 cwd,
2294 ["log", "--oneline", range],
2296 ["log", "--oneline", commitRange],
22952297 {
22962298 maxOutputBytes: RANGE_COMMIT_SUMMARY_MAX_OUTPUT_BYTES,
22972299 appendTruncationMarker: true,
......@@ -2300,7 +2302,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
23002302 runGitStdoutWithOptions(
23012303 "GitVcsDriver.readRangeContext.diffStat",
23022304 cwd,
2303 ["diff", "--stat", range],
2305 ["diff", "--stat", diffRange],
23042306 {
23052307 maxOutputBytes: RANGE_DIFF_SUMMARY_MAX_OUTPUT_BYTES,
23062308 appendTruncationMarker: true,
......@@ -2309,7 +2311,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
23092311 runGitStdoutWithOptions(
23102312 "GitVcsDriver.readRangeContext.diffPatch",
23112313 cwd,
2312 ["diff", "--no-ext-diff", "--patch", "--minimal", range],
2314 ["diff", "--no-ext-diff", "--patch", "--minimal", diffRange],
23132315 {
23142316 maxOutputBytes: RANGE_DIFF_PATCH_MAX_OUTPUT_BYTES,
23152317 appendTruncationMarker: true,