diff --git a/packages/source-control-core/src/server/diffFileRevisions.test.ts b/packages/source-control-core/src/server/diffFileRevisions.test.ts index f14b52f8c9acb..6959d8e2ffc14 100644 --- a/packages/source-control-core/src/server/diffFileRevisions.test.ts +++ b/packages/source-control-core/src/server/diffFileRevisions.test.ts @@ -40,6 +40,20 @@ describe("truncateLongDiffLines", () => { }); describe("parseDiffFileRevisions", () => { + it("locates a pure copy when a path contains the header separator", () => { + const patch = patchOf( + "diff --git a/source.txt b/folder b/copy.txt", + "similarity index 100%", + "copy from source.txt", + "copy to folder b/copy.txt", + ); + + assert.deepStrictEqual(parseDiffFilePaths(patch), [ + { oldPath: "source.txt", newPath: "folder b/copy.txt" }, + ]); + assert.strictEqual(diffFileSection(patch, "folder b/copy.txt"), patch); + }); + it("reads the head id of a changed file off its index line", () => { const revisions = parseDiffFileRevisions( patchOf( diff --git a/packages/source-control-core/src/server/diffFileRevisions.ts b/packages/source-control-core/src/server/diffFileRevisions.ts index 31c57d975ba35..4c2324f5481c1 100644 --- a/packages/source-control-core/src/server/diffFileRevisions.ts +++ b/packages/source-control-core/src/server/diffFileRevisions.ts @@ -94,6 +94,10 @@ function parseEntries(patch: string): ReadonlyArray> { entry.revision = headRevision(line.slice("index ".length)); } else if (line.startsWith("deleted file mode")) { entry.deleted = true; + } else if (line.startsWith("copy from ")) { + entry.oldPath = unquoteGitPatchPath(line.slice("copy from ".length)); + } else if (line.startsWith("copy to ")) { + entry.newPath = unquoteGitPatchPath(line.slice("copy to ".length)); } else if (line.startsWith("rename from ")) { entry.oldPath = unquoteGitPatchPath(line.slice("rename from ".length)); } else if (line.startsWith("rename to ")) {