fix(server): keep commit file paths when a file moves up a directory

This commit is contained in:
hadan8977
2026-11-02 02:23:08 +00:00
committed by paseo-bot[bot]
parent efc64a5443
commit 5b495fe868
2 changed files with 19 additions and 1 deletions
@@ -332,6 +332,21 @@ describe("listCheckoutCommits", () => {
]);
});
it("keeps the destination path when a file moves up out of a directory", async () => {
const { repoDir } = initRepoOnMain();
git(["checkout", "-b", "feature"], repoDir);
mkdirSync(join(repoDir, "src", "nested"), { recursive: true });
commitFile(repoDir, "src/nested/a.txt", "content\n", "Add nested file");
git(["mv", "src/nested/a.txt", "src/a.txt"], repoDir);
commit(repoDir, "Move file up");
const { commits } = await listCheckoutCommits({ cwd: repoDir });
expect(commits[0]?.files).toEqual([
{ path: "src/a.txt", additions: 0, deletions: 0, status: "renamed" },
]);
});
it("derives status for modified and deleted files", async () => {
const { repoDir } = initRepoOnMain();
git(["checkout", "-b", "feature"], repoDir);
+4 -1
View File
@@ -636,7 +636,10 @@ function normalizeNumstatPath(pathField: string): string {
const braceRenameMatch = pathField.match(/^(.*)\{(.*) => (.*)\}(.*)$/);
if (braceRenameMatch) {
const [, prefix, , renamed, suffix] = braceRenameMatch;
return unquoteGitPath(`${prefix}${renamed}${suffix}`);
// Moving out of a directory prints `src/{nested => }/a.ts`, so an empty
// destination leaves a separator from each side behind.
const destination = renamed ? `${prefix}${renamed}${suffix}` : `${prefix}${suffix.slice(1)}`;
return unquoteGitPath(destination);
}
const inlineRenameMatch = pathField.match(/^(.*) => (.*)$/);