From 0e3106a004960f0122e57d0a20fdfce7f277dd4d Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 02:34:09 +0000 Subject: [PATCH] refactor(git): clarify compact rename handling and test cases Co-authored-by: hadan8977 --- .../src/utils/checkout-git.commits.test.ts | 28 +++++++++++-------- packages/server/src/utils/checkout-git.ts | 6 ++-- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/server/src/utils/checkout-git.commits.test.ts b/packages/server/src/utils/checkout-git.commits.test.ts index 7e50f81483..7baac91c23 100644 --- a/packages/server/src/utils/checkout-git.commits.test.ts +++ b/packages/server/src/utils/checkout-git.commits.test.ts @@ -332,18 +332,24 @@ describe("listCheckoutCommits", () => { ]); }); - it.each([false, true])( - "opens a file moved up out of a directory (edited: %s)", - async (edited) => { + it.each([ + { + label: "without edits", + content: "one\ntwo\nthree\nfour\nfive\n", + additions: 0, + deletions: 0, + }, + { label: "with edits", content: "one\nTWO\nthree\nfour\nfive\n", additions: 1, deletions: 1 }, + ])( + "opens a file moved up out of a directory $label", + async ({ content, additions, deletions }) => { const { repoDir } = initRepoOnMain(); git(["checkout", "-b", "feature"], repoDir); mkdirSync(join(repoDir, "src", "nested"), { recursive: true }); commitFile(repoDir, "src/nested/a.txt", "one\ntwo\nthree\nfour\nfive\n", "Add nested file"); git(["mv", "src/nested/a.txt", "src/a.txt"], repoDir); - if (edited) { - writeFileSync(join(repoDir, "src/a.txt"), "one\nTWO\nthree\nfour\nfive\n"); - git(["add", "src/a.txt"], repoDir); - } + writeFileSync(join(repoDir, "src/a.txt"), content); + git(["add", "src/a.txt"], repoDir); commit(repoDir, "Move file up"); const { commits } = await listCheckoutCommits({ cwd: repoDir }); @@ -353,8 +359,8 @@ describe("listCheckoutCommits", () => { expect(movedCommit.files).toEqual([ { path: "src/a.txt", - additions: edited ? 1 : 0, - deletions: edited ? 1 : 0, + additions, + deletions, status: "renamed", }, ]); @@ -364,8 +370,8 @@ describe("listCheckoutCommits", () => { path: "src/a.txt", isNew: false, isDeleted: false, - additions: edited ? 1 : 0, - deletions: edited ? 1 : 0, + additions, + deletions, }); }, ); diff --git a/packages/server/src/utils/checkout-git.ts b/packages/server/src/utils/checkout-git.ts index 31be4cdfc3..bd25f46770 100644 --- a/packages/server/src/utils/checkout-git.ts +++ b/packages/server/src/utils/checkout-git.ts @@ -638,8 +638,10 @@ function normalizeNumstatPath(pathField: string): string { const [, prefix, , renamed, suffix] = braceRenameMatch; // 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); + if (!renamed) { + return unquoteGitPath(`${prefix}${suffix.slice(1)}`); + } + return unquoteGitPath(`${prefix}${renamed}${suffix}`); } const inlineRenameMatch = pathField.match(/^(.*) => (.*)$/);