Skip to content
TypeScript

fix(server): diffs keep blank context lines under diff.suppressBlankEmpty (#29579)

Alex Southwell35af84977d0e
diff --git a/apps/server/src/checkpointing/CheckpointStore.test.ts b/apps/server/src/checkpointing/CheckpointStore.test.ts
index c2a72bcf5f0..51c461d4a6d 100644
--- a/apps/server/src/checkpointing/CheckpointStore.test.ts
+++ b/apps/server/src/checkpointing/CheckpointStore.test.ts
@@ -153,21 +153,23 @@ it.layer(layerTest)("CheckpointStore.layer", (it) => {
}),
);
- it.effect("keeps a/ and b/ patch prefixes when the repository disables them", () =>
+ it.effect("keeps the patch format clients parse when the repository changes it", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
yield* git(tmp, ["config", "diff.noprefix", "true"]);
+ yield* git(tmp, ["config", "diff.suppressBlankEmpty", "true"]);
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("thread-checkpoint-store-noprefix");
const fromCheckpointRef = checkpointRefForThreadTurn(threadId, 0);
const toCheckpointRef = checkpointRefForThreadTurn(threadId, 1);
+ yield* writeTextFile(NodePath.join(tmp, "README.md"), "# test\n\nbefore\n");
yield* checkpointStore.captureCheckpoint({
cwd: tmp,
checkpointRef: fromCheckpointRef,
});
- yield* writeTextFile(NodePath.join(tmp, "README.md"), "# changed\n");
+ yield* writeTextFile(NodePath.join(tmp, "README.md"), "# test\n\nafter\n");
yield* checkpointStore.captureCheckpoint({
cwd: tmp,
checkpointRef: toCheckpointRef,
@@ -181,6 +183,7 @@ it.layer(layerTest)("CheckpointStore.layer", (it) => {
});
expect(diff).toContain("diff --git a/README.md b/README.md");
+ expect(diff).toContain(" # test\n \n-before\n+after\n");
}),
);
diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts
index ac01dc6e228..db53eaf2be3 100644
--- a/apps/server/src/vcs/GitVcsDriver.ts
+++ b/apps/server/src/vcs/GitVcsDriver.ts
@@ -1377,6 +1377,8 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
// Not --no-relative, which Git before 2.28 rejects.
"-c",
"diff.relative=false",
+ "-c",
+ "diff.suppressBlankEmpty=false",
"diff",
...(input.format === "numstat" ? ["--numstat", "-z"] : ["--patch"]),
"--no-color",
diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts
index 654d98db8f1..aa98a53b127 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts
@@ -2397,18 +2397,19 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
}),
);
- it.effect("keeps a/ and b/ patch prefixes when the repository disables them", () =>
+ it.effect("keeps the patch format clients parse when the repository changes it", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
const { initialBranch } = yield* initRepoWithCommit(cwd);
const driver = yield* GitVcsDriver.GitVcsDriver;
yield* git(cwd, ["config", "diff.noprefix", "true"]);
yield* git(cwd, ["config", "diff.mnemonicPrefix", "true"]);
+ yield* git(cwd, ["config", "diff.suppressBlankEmpty", "true"]);
yield* git(cwd, ["checkout", "-b", "feature/noprefix"]);
- yield* writeTextFile(cwd, "README.md", "# committed change\n");
+ yield* writeTextFile(cwd, "README.md", "# test\n\ncommitted change\n");
yield* git(cwd, ["add", "README.md"]);
yield* git(cwd, ["commit", "-m", "committed change"]);
- yield* writeTextFile(cwd, "README.md", "# dirty change\n");
+ yield* writeTextFile(cwd, "README.md", "# test\n\ndirty change\n");
yield* writeTextFile(cwd, "untracked.txt", "untracked\n");
const preview = yield* driver.getReviewDiffPreview({
@@ -2420,6 +2421,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
const workingTree = preview.sources.find((source) => source.kind === "working-tree")?.diff;
const branchRange = preview.sources.find((source) => source.kind === "branch-range")?.diff;
assert.include(workingTree, "diff --git a/README.md b/README.md");
+ assert.include(workingTree, " # test\n \n-committed change\n+dirty change\n");
assert.include(workingTree, "+++ b/untracked.txt");
assert.include(branchRange, "diff --git a/README.md b/README.md");
}),
diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts
index cb7814d4c54..6cc5266ff15 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.ts
@@ -81,7 +81,10 @@ const REVIEW_BRANCH_SUBJECT_LIMIT = 300;
const REVIEW_BRANCH_COMMIT_MAX_OUTPUT_BYTES = 128 * 1024;
// Client patch parsers require a/ and b/ prefixes; override user diff prefix settings.
export const PATCH_RENDER_PREFIX_ARGS = ["--src-prefix=a/", "--dst-prefix=b/"] as const;
+// Client patch parsers drop blank context lines that diff.suppressBlankEmpty prints without a space.
const REVIEW_DIFF_ARGS = [
+ "-c",
+ "diff.suppressBlankEmpty=false",
"diff",
"--find-renames",
"--no-color",