Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe("azureDevOpsFilePatch", () => {
expect(patch.section).toBe(
[
"diff --git a/docs/old.md b/docs/new.md",
"similarity index 100%",
"rename from docs/old.md",
"rename to docs/new.md",
"--- a/docs/old.md",
Expand Down Expand Up @@ -209,6 +210,7 @@ describe("a file Azure names something a patch header cannot carry plainly", ()
expect(patch.section).toBe(
[
'diff --git "a/docs/old\\tname.md" "b/docs/new\\tname.md"',
"similarity index 100%",
'rename from "docs/old\\tname.md"',
'rename to "docs/new\\tname.md"',
'--- "a/docs/old\\tname.md"',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ function patchHeader(change: AzureDevOpsChangeEntry): string {
if (change.changeKind === "new") lines.push("new file mode 100644");
if (change.changeKind === "deleted") lines.push("deleted file mode 100644");
if (change.changeKind === "rename-pure" || change.changeKind === "rename-changed") {
// Pierre needs this header to keep the rename.
lines.push(
`similarity index ${change.changeKind === "rename-pure" ? 100 : 0}%`,
`rename from ${quoteGitPatchPath(change.oldPath)}`,
`rename to ${quoteGitPatchPath(change.path)}`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,7 @@ describe("decodePullRequestFilesJson", () => {
expect(result.patch).toBe(
[
String.raw`diff --git "a/ old\\name.ts " "b/ new\\name.ts "`,
"similarity index 100%",
String.raw`rename from " old\\name.ts "`,
String.raw`rename to " new\\name.ts "`,
String.raw`--- "a/ old\\name.ts "`,
Expand Down Expand Up @@ -1515,6 +1516,7 @@ describe("decodePullRequestFilesJson", () => {
expect(result.patch).toBe(
[
"diff --git a/src/old.ts b/src/new.ts",
"similarity index 0%",
"rename from src/old.ts",
"rename to src/new.ts",
"--- a/src/old.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,8 @@ function toFilesPatch(entries: ReadonlyArray<unknown>): GitHubPullRequestFilesPa
...(status === "removed" ? ["deleted file mode 100644"] : []),
...(status === "renamed"
? [
// The files API has no similarity score; Pierre needs this header to keep the rename.
`similarity index ${hunks.length > 0 || (value.additions ?? 0) + (value.deletions ?? 0) > 0 ? 0 : 100}%`,
`rename from ${quoteGitPatchPath(oldPath)}`,
`rename to ${quoteGitPatchPath(value.filename)}`,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ describe("decodeMergeRequestDiffsJson", () => {
expect(result.patch).toBe(
[
String.raw`diff --git "a/ old\\name.ts " "b/ new\\name.ts "`,
"similarity index 100%",
String.raw`rename from " old\\name.ts "`,
String.raw`rename to " new\\name.ts "`,
String.raw`--- "a/ old\\name.ts "`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ function mergeRequestPatch(entries: ReadonlyArray<unknown>): GitLabMergeRequestP
...(value.deleted_file === true ? [`deleted file mode ${value.a_mode ?? "100644"}`] : []),
...(value.renamed_file === true
? [
// GitLab has no similarity score; Pierre needs this header to keep the rename.
`similarity index ${hunks.length > 0 || value.too_large === true || value.collapsed === true ? 0 : 100}%`,
`rename from ${quoteGitPatchPath(value.old_path)}`,
`rename to ${quoteGitPatchPath(value.new_path)}`,
]
Expand Down
Loading