Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/local-vcs/src/vcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,9 @@ async function readGitDiff(input: {
"--no-ext-diff",
"--no-textconv",
"--no-color",
// Pinned: diff.mnemonicPrefix, diff.noprefix and diff.srcPrefix change them.
"--src-prefix=a/",
"--dst-prefix=b/",
"-M",
...(input.contextLines !== undefined
? [`--unified=${input.contextLines}`]
Expand Down
50 changes: 49 additions & 1 deletion packages/local-vcs/src/working-diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import path from "node:path";

import { expect, it } from "vitest";

import { diffFileSummariesWorkingTree, diffWorkingTree } from "./index";
import {
diffFileSummariesWorkingTree,
diffWorkingTree,
splitGitPatchFiles,
} from "./index";

it.each([false, true])(
"diffs final working bytes without modifying repository state (split index: %s)",
Expand Down Expand Up @@ -218,3 +222,47 @@ it("sees a same-size rewrite that only Git's racy-index check can catch", async
await rm(root, { recursive: true, force: true });
}
});

it.each(["diff.mnemonicPrefix", "diff.noprefix"])(
"keeps a/ and b/ patch prefixes when the user's Git config sets %s",
async (setting) => {
const root = await mkdtemp(path.join(tmpdir(), "working-diff-prefix-"));

const git = (...args: string[]) =>
execFileSync("git", ["-C", root, ...args], { encoding: "utf8" }).trim();

try {
git("init", "-q");
await mkdir(path.join(root, "a"));
await writeFile(path.join(root, "a", "util.ts"), "base\n");
await writeFile(path.join(root, "app.ts"), "base\n");
git("add", ".");
git(
"-c",
"user.name=Test",
"-c",
"user.email=test@example.invalid",
"-c",
"commit.gpgsign=false",
"commit",
"-qm",
"base",
);
await writeFile(path.join(root, "a", "util.ts"), "working\n");
await writeFile(path.join(root, "app.ts"), "working\n");
git("config", setting, "true");

const patch = await diffWorkingTree({
rootPath: root,
kind: "git",
baseRef: git("rev-parse", "HEAD"),
});

expect(splitGitPatchFiles(patch).map((entry) => entry.file.path)).toEqual(
["a/util.ts", "app.ts"],
);
} finally {
await rm(root, { recursive: true, force: true });
}
},
);