| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b080622 commit fc8ff1f
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -524,7 +524,20 @@ | |||
| 524 | 524 | "ignore": true | |
| 525 | 525 | }, | |
| 526 | 526 | "git_diff_find_similar": { | |
| 527 | - "ignore": true | ||
| 527 | + "args": { | ||
| 528 | + "diff": { | ||
| 529 | + "isSelf": true | ||
| 530 | + }, | ||
| 531 | + "options": { | ||
| 532 | + "isOptional": true | ||
| 533 | + } | ||
| 534 | + }, | ||
| 535 | + "return": { | ||
| 536 | + "cppClassName": "Number", | ||
| 537 | + "jsClassName": "Number", | ||
| 538 | + "isErrorCode": true | ||
| 539 | + }, | ||
| 540 | + "isAsync": true | ||
| 528 | 541 | }, | |
| 529 | 542 | "git_diff_foreach": { | |
| 530 | 543 | "ignore": true | |
@@ -639,12 +652,12 @@ | |||
| 639 | 652 | } | |
| 640 | 653 | }, | |
| 641 | 654 | "diff_find_options": { | |
| 655 | + "hasConstructor": true, | ||
| 642 | 656 | "fields": { | |
| 643 | 657 | "git_diff_similarity_metric": { | |
| 644 | 658 | "ignore": true | |
| 645 | 659 | } | |
| 646 | - }, | ||
| 647 | - "ignore": true | ||
| 660 | + } | ||
| 648 | 661 | }, | |
| 649 | 662 | "diff_format_email_options": { | |
| 650 | 663 | "ignore": true | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,4 +56,11 @@ Diff.treeToWorkdirWithIndex = function(repo, tree, opts) { | |||
| 56 | 56 | return treeToWorkdirWithIndex(repo, tree, opts); | |
| 57 | 57 | }; | |
| 58 | 58 | ||
| 59 | + // Override Diff.findSimilar to normalize opts | ||
| 60 | + var findSimilar = Diff.prototype.findSimilar; | ||
| 61 | + Diff.prototype.findSimilar = function(opts) { | ||
| 62 | + opts = normalizeOptions(opts, NodeGit.DiffFindOptions); | ||
| 63 | + return findSimilar.call(this, opts); | ||
| 64 | + }; | ||
| 65 | + | ||
| 59 | 66 | module.exports = Diff; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,12 @@ describe("Diff", function() { | |||
| 14 | 14 | var diffFilename = "wddiff.txt"; | |
| 15 | 15 | var diffFilepath = local("../repos/workdir", diffFilename); | |
| 16 | 16 | ||
| 17 | + var moveFromFile = "README.md"; | ||
| 18 | + var moveToFile = "MOVED_README.md"; | ||
| 19 | + | ||
| 20 | + var moveFromPath = local("../repos/workdir", moveFromFile); | ||
| 21 | + var moveToPath = local("../repos/workdir", moveToFile); | ||
| 22 | + | ||
| 17 | 23 | beforeEach(function() { | |
| 18 | 24 | var test = this; | |
| 19 | 25 | ||
@@ -45,6 +51,9 @@ describe("Diff", function() { | |||
| 45 | 51 | ||
| 46 | 52 | return fse.writeFile(diffFilepath, "1 line\n2 line\n3 line\n\n4"); | |
| 47 | 53 | }) | |
| 54 | + .then(function() { | ||
| 55 | + return fse.move(moveFromPath, moveToPath); | ||
| 56 | + }) | ||
| 48 | 57 | .then(function() { | |
| 49 | 58 | return Diff.treeToWorkdirWithIndex( | |
| 50 | 59 | test.repository, | |
@@ -56,7 +65,10 @@ describe("Diff", function() { | |||
| 56 | 65 | test.workdirDiff = workdirDiff; | |
| 57 | 66 | }) | |
| 58 | 67 | .then(function() { | |
| 59 | - var opts = { flags: Diff.OPTION.INCLUDE_UNTRACKED }; | ||
| 68 | + var opts = { | ||
| 69 | + flags: Diff.OPTION.INCLUDE_UNTRACKED | | ||
| 70 | + Diff.OPTION.RECURSE_UNTRACKED_DIRS | ||
| 71 | + }; | ||
| 60 | 72 | ||
| 61 | 73 | return Diff.indexToWorkdir(test.repository, test.index, opts); | |
| 62 | 74 | }) | |
@@ -66,6 +78,9 @@ describe("Diff", function() { | |||
| 66 | 78 | .then(function() { | |
| 67 | 79 | return fse.remove(diffFilepath); | |
| 68 | 80 | }) | |
| 81 | + .then(function() { | ||
| 82 | + return fse.move(moveToPath, moveFromPath); | ||
| 83 | + }) | ||
| 69 | 84 | .catch(function(e) { | |
| 70 | 85 | return fse.remove(diffFilepath) | |
| 71 | 86 | .then(function() { | |
@@ -106,14 +121,14 @@ describe("Diff", function() { | |||
| 106 | 121 | ||
| 107 | 122 | it("can diff the workdir with index", function() { | |
| 108 | 123 | var patches = this.workdirDiff.patches(); | |
| 109 | - assert.equal(patches.length, 1); | ||
| 110 | - assert(patches[0].isUntracked()); | ||
| 124 | + assert.equal(patches.length, 3); | ||
| 125 | + assert(patches[2].isUntracked()); | ||
| 111 | 126 | ||
| 112 | - var oldFile = patches[0].delta.oldFile(); | ||
| 127 | + var oldFile = patches[2].delta.oldFile(); | ||
| 113 | 128 | assert.equal(oldFile.path(), "wddiff.txt"); | |
| 114 | 129 | assert.equal(oldFile.size(), 0); | |
| 115 | 130 | ||
| 116 | - var newFile = patches[0].delta.newFile(); | ||
| 131 | + var newFile = patches[2].delta.newFile(); | ||
| 117 | 132 | assert.equal(newFile.path(), "wddiff.txt"); | |
| 118 | 133 | assert.equal(newFile.size(), 23); | |
| 119 | 134 | }); | |
@@ -151,6 +166,22 @@ describe("Diff", function() { | |||
| 151 | 166 | }); | |
| 152 | 167 | ||
| 153 | 168 | it("can diff index to workdir", function() { | |
| 154 | - assert.equal(this.indexToWorkdirDiff.patches().length, 1); | ||
| 169 | + assert.equal(this.indexToWorkdirDiff.patches().length, 3); | ||
| 170 | + }); | ||
| 171 | + | ||
| 172 | + it("can find similar files in a diff", function() { | ||
| 173 | + var diff = this.indexToWorkdirDiff; | ||
| 174 | + var opts = { | ||
| 175 | + flags: Diff.FIND.RENAMES | | ||
| 176 | + Diff.FIND.RENAMES_FROM_REWRITES | | ||
| 177 | + Diff.FIND.FOR_UNTRACKED | ||
| 178 | + }; | ||
| 179 | + | ||
| 180 | + assert.equal(diff.patches().length, 3); | ||
| 181 | + | ||
| 182 | + diff.findSimilar(opts).then(function() { | ||
| 183 | + // Renamed file now treated as one diff, so 3 patches -> 2 | ||
| 184 | + assert.equal(diff.patches().length, 2); | ||
| 185 | + }); | ||
| 155 | 186 | }); | |
| 156 | 187 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments