TypeScript
fix(server): keep a/ and b/ prefixes in rendered git patches (#9438)
Igor Makowski36c4e9cf5c01
diff --git a/apps/server/src/checkpointing/CheckpointStore.test.ts b/apps/server/src/checkpointing/CheckpointStore.test.tsindex bf332d20d0d..2f46858986a 100644--- a/apps/server/src/checkpointing/CheckpointStore.test.ts+++ b/apps/server/src/checkpointing/CheckpointStore.test.ts@@ -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();diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.tsindex 1ab42434763..08b474cf42d 100644--- a/apps/server/src/vcs/GitVcsDriver.ts+++ b/apps/server/src/vcs/GitVcsDriver.ts@@ -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}`,diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.tsindex c0621f2c99d..8e76413496b 100644--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts@@ -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();diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.tsindex f1fb1b7a7b1..3a4a172a643 100644--- a/apps/server/src/vcs/GitVcsDriverCore.ts+++ b/apps/server/src/vcs/GitVcsDriverCore.ts@@ -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`,],