fix(server): keep a/ and b/ prefixes in rendered git patches (#9438)

This commit is contained in:
Igor Makowski authored and GitHub committed 2026-09-03 15:23:53 -05:00
1 parent de025aa69f
commit 36c4e9cf5c
4 files changed
+72 -1

No files matched your search

@@ -147,6 +147,37 @@ it.layer(TestLayer)("CheckpointStore.layer", (it) => {
}),
);
it.effect("keeps a/ and b/ patch prefixes when the repository disables them", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
yield* git(tmp, ["config", "diff.noprefix", "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* checkpointStore.captureCheckpoint({
cwd: tmp,
checkpointRef: fromCheckpointRef,
});
yield* writeTextFile(NodePath.join(tmp, "README.md"), "# changed\n");
yield* checkpointStore.captureCheckpoint({
cwd: tmp,
checkpointRef: toCheckpointRef,
});
const diff = yield* checkpointStore.diffCheckpoints({
cwd: tmp,
fromCheckpointRef,
toCheckpointRef,
ignoreWhitespace: false,
});
expect(diff).toContain("diff --git a/README.md b/README.md");
}),
);
it.effect("can hide indentation churn when changes wrap existing lines", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
+6 -1
View File
@@ -30,7 +30,11 @@ import {
type VcsStatusInput,
type VcsStatusResult,
} from "@t3tools/contracts";
import { makeGitVcsDriverCore, splitNullSeparatedGitStdoutPaths } from "./GitVcsDriverCore.ts";
import {
makeGitVcsDriverCore,
PATCH_RENDER_PREFIX_ARGS,
splitNullSeparatedGitStdoutPaths,
} from "./GitVcsDriverCore.ts";
import * as VcsDriver from "./VcsDriver.ts";
import * as VcsProcess from "./VcsProcess.ts";
@@ -869,6 +873,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
"--no-color",
"--no-ext-diff",
"--no-textconv",
...PATCH_RENDER_PREFIX_ARGS,
...(input.ignoreWhitespace ? ["--ignore-all-space"] : []),
`${fromRevision}^{commit}`,
`${input.toCheckpointRef}^{commit}`,
@@ -819,6 +819,34 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
}),
);
it.effect("keeps a/ and b/ patch prefixes when the repository disables them", () =>
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, ["checkout", "-b", "feature/noprefix"]);
yield* writeTextFile(cwd, "README.md", "# committed 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, "untracked.txt", "untracked\n");
const preview = yield* driver.getReviewDiffPreview({
cwd,
baseRef: initialBranch,
ignoreWhitespace: false,
});
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, "+++ b/untracked.txt");
assert.include(branchRange, "diff --git a/README.md b/README.md");
}),
);
it.effect("loads full file contents for working-tree diff expansion", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
+7
View File
@@ -52,6 +52,10 @@ const RANGE_DIFF_PATCH_MAX_OUTPUT_BYTES = 59_000;
const REVIEW_DIFF_PATCH_MAX_OUTPUT_BYTES = 120_000;
const REVIEW_UNTRACKED_DIFF_MAX_OUTPUT_BYTES = 80_000;
const REVIEW_DIFF_FILE_MAX_OUTPUT_BYTES = 1024 * 1024;
// Patches the clients render are parsed against git's default a/ and b/ path
// prefixes. A repository or global diff.noprefix or diff.mnemonicPrefix would
// otherwise leak into the patch and leave every parsed file unnamed.
export const PATCH_RENDER_PREFIX_ARGS = ["--src-prefix=a/", "--dst-prefix=b/"] as const;
const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 120_000;
const STATUS_UPSTREAM_REFRESH_INTERVAL = Duration.seconds(15);
const STATUS_UPSTREAM_REFRESH_TIMEOUT = Duration.seconds(5);
@@ -2205,6 +2209,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
"--no-ext-diff",
"--no-textconv",
"--minimal",
...PATCH_RENDER_PREFIX_ARGS,
"--",
"/dev/null",
relativePath,
@@ -2257,6 +2262,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
"--no-ext-diff",
"--no-textconv",
"--minimal",
...PATCH_RENDER_PREFIX_ARGS,
...(input.ignoreWhitespace ? ["--ignore-all-space"] : []),
"HEAD",
"--",
@@ -2293,6 +2299,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
"--no-ext-diff",
"--no-textconv",
"--minimal",
...PATCH_RENDER_PREFIX_ARGS,
...(input.ignoreWhitespace ? ["--ignore-all-space"] : []),
`${baseRef}...HEAD`,
],