Skip to content

Commit 8bfe94a

Browse files
saphidclaudemaria-rcks
authored
fix(source-control): renamed files in GitHub, GitLab and Azure DevOps diffs show as renames (pingdotgg#29774)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 136fe43 commit 8bfe94a

6 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎packages/source-control-azure-devops/src/server/azureDevOpsDiff.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ describe("azureDevOpsFilePatch", () => {
8080
expect(patch.section).toBe(
8181
[
8282
"diff --git a/docs/old.md b/docs/new.md",
83+
"similarity index 100%",
8384
"rename from docs/old.md",
8485
"rename to docs/new.md",
8586
"--- a/docs/old.md",
@@ -209,6 +210,7 @@ describe("a file Azure names something a patch header cannot carry plainly", ()
209210
expect(patch.section).toBe(
210211
[
211212
'diff --git "a/docs/old\\tname.md" "b/docs/new\\tname.md"',
213+
"similarity index 100%",
212214
'rename from "docs/old\\tname.md"',
213215
'rename to "docs/new\\tname.md"',
214216
'--- "a/docs/old\\tname.md"',

‎packages/source-control-azure-devops/src/server/azureDevOpsDiff.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ function patchHeader(change: AzureDevOpsChangeEntry): string {
9191
if (change.changeKind === "new") lines.push("new file mode 100644");
9292
if (change.changeKind === "deleted") lines.push("deleted file mode 100644");
9393
if (change.changeKind === "rename-pure" || change.changeKind === "rename-changed") {
94+
// Pierre needs this header to keep the rename.
9495
lines.push(
96+
`similarity index ${change.changeKind === "rename-pure" ? 100 : 0}%`,
9597
`rename from ${quoteGitPatchPath(change.oldPath)}`,
9698
`rename to ${quoteGitPatchPath(change.path)}`,
9799
);

‎packages/source-control-github/src/server/gitHubPullRequestJson.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,7 @@ describe("decodePullRequestFilesJson", () => {
14601460
expect(result.patch).toBe(
14611461
[
14621462
String.raw`diff --git "a/ old\\name.ts " "b/ new\\name.ts "`,
1463+
"similarity index 100%",
14631464
String.raw`rename from " old\\name.ts "`,
14641465
String.raw`rename to " new\\name.ts "`,
14651466
String.raw`--- "a/ old\\name.ts "`,
@@ -1515,6 +1516,7 @@ describe("decodePullRequestFilesJson", () => {
15151516
expect(result.patch).toBe(
15161517
[
15171518
"diff --git a/src/old.ts b/src/new.ts",
1519+
"similarity index 0%",
15181520
"rename from src/old.ts",
15191521
"rename to src/new.ts",
15201522
"--- a/src/old.ts",

‎packages/source-control-github/src/server/gitHubPullRequestJson.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,8 @@ function toFilesPatch(entries: ReadonlyArray<unknown>): GitHubPullRequestFilesPa
16391639
...(status === "removed" ? ["deleted file mode 100644"] : []),
16401640
...(status === "renamed"
16411641
? [
1642+
// The files API has no similarity score; Pierre needs this header to keep the rename.
1643+
`similarity index ${hunks.length > 0 || (value.additions ?? 0) + (value.deletions ?? 0) > 0 ? 0 : 100}%`,
16421644
`rename from ${quoteGitPatchPath(oldPath)}`,
16431645
`rename to ${quoteGitPatchPath(value.filename)}`,
16441646
]

‎packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ describe("decodeMergeRequestDiffsJson", () => {
372372
expect(result.patch).toBe(
373373
[
374374
String.raw`diff --git "a/ old\\name.ts " "b/ new\\name.ts "`,
375+
"similarity index 100%",
375376
String.raw`rename from " old\\name.ts "`,
376377
String.raw`rename to " new\\name.ts "`,
377378
String.raw`--- "a/ old\\name.ts "`,

‎packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ function mergeRequestPatch(entries: ReadonlyArray<unknown>): GitLabMergeRequestP
724724
...(value.deleted_file === true ? [`deleted file mode ${value.a_mode ?? "100644"}`] : []),
725725
...(value.renamed_file === true
726726
? [
727+
// GitLab has no similarity score; Pierre needs this header to keep the rename.
728+
`similarity index ${hunks.length > 0 || value.too_large === true || value.collapsed === true ? 0 : 100}%`,
727729
`rename from ${quoteGitPatchPath(value.old_path)}`,
728730
`rename to ${quoteGitPatchPath(value.new_path)}`,
729731
]

0 commit comments

Comments
 (0)