Skip to content

Commit 2526c2d

Browse files
committed
fix(server): generate PR diffs from branch changes
Port upstream f223312 (pingdotgg#13170). Keep commit logs two-dot and compute PR patches from the common ancestor. Model: gpt-6.1-sol Task: bugfix Agent: issue699-handoff4
1 parent 569116e commit 2526c2d

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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,14 +4103,24 @@ 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: ["[]", "[]"],
41104118
},
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‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

0 commit comments

Comments
 (0)