mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-02 22:52:58 +00:00
fix(server): keep commit file paths when a file moves up a directory
This commit is contained in:
committed by
paseo-bot[bot]
parent
efc64a5443
commit
5b495fe868
@@ -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);
|
||||
|
||||
@@ -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(/^(.*) => (.*)$/);
|
||||
|
||||
Reference in New Issue
Block a user