| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -741,7 +741,15 @@ | |||
| 741 | 741 | "ignore": true | |
| 742 | 742 | }, | |
| 743 | 743 | "git_diff_merge": { | |
| 744 | - "ignore": true | ||
| 744 | + "isAsync": true, | ||
| 745 | + "args": { | ||
| 746 | + "onto": { | ||
| 747 | + "isSelf": true | ||
| 748 | + } | ||
| 749 | + }, | ||
| 750 | + "return": { | ||
| 751 | + "isErrorCode": true | ||
| 752 | + } | ||
| 745 | 753 | }, | |
| 746 | 754 | "git_diff_num_deltas_of_type": { | |
| 747 | 755 | "ignore": true | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,31 @@ | |||
| 1 | 1 | var assert = require("assert"); | |
| 2 | 2 | var path = require("path"); | |
| 3 | 3 | var promisify = require("promisify-node"); | |
| 4 | + var _ = require("lodash"); | ||
| 4 | 5 | var fse = promisify(require("fs-extra")); | |
| 5 | 6 | var local = path.join.bind(path, __dirname); | |
| 6 | 7 | ||
| 8 | + function getLinesFromDiff(diff) { | ||
| 9 | + return diff.patches() | ||
| 10 | + .then(function(patches) { | ||
| 11 | + return Promise.all(_.map(patches, function(patch) { | ||
| 12 | + return patch.hunks(); | ||
| 13 | + })); | ||
| 14 | + }) | ||
| 15 | + .then(function(listsOfHunks) { | ||
| 16 | + var hunks = _.flatten(listsOfHunks); | ||
| 17 | + return Promise.all(_.map(hunks, function(hunk) { | ||
| 18 | + return hunk.lines(); | ||
| 19 | + })); | ||
| 20 | + }) | ||
| 21 | + .then(function(listsOfLines) { | ||
| 22 | + var lines = _.flatten(listsOfLines); | ||
| 23 | + return _.map(lines, function(line) { | ||
| 24 | + return line.content(); | ||
| 25 | + }); | ||
| 26 | + }); | ||
| 27 | + } | ||
| 28 | + | ||
| 7 | 29 | describe("Diff", function() { | |
| 8 | 30 | var NodeGit = require("../../"); | |
| 9 | 31 | var Repository = NodeGit.Repository; | |
@@ -144,7 +166,7 @@ describe("Diff", function() { | |||
| 144 | 166 | }); | |
| 145 | 167 | }); | |
| 146 | 168 | ||
| 147 | - it("can resolve individual line chages from the patch hunks", function() { | ||
| 169 | + it("can resolve individual line changes from the patch hunks", function() { | ||
| 148 | 170 | return this.workdirDiff.patches() | |
| 149 | 171 | .then(function(patches) { | |
| 150 | 172 | var result = []; | |
@@ -326,6 +348,43 @@ describe("Diff", function() { | |||
| 326 | 348 | }); | |
| 327 | 349 | }); | |
| 328 | 350 | ||
| 351 | + | ||
| 352 | + it("can merge two diffs", function() { | ||
| 353 | + var linesOfFirstDiff; | ||
| 354 | + var linesOfSecondDiff; | ||
| 355 | + var firstDiff = this.diff[0]; | ||
| 356 | + var secondDiff; | ||
| 357 | + var oid = "c88d39e70585199425b111c6a2c7fa7b4bc617ad"; | ||
| 358 | + return this.repository.getCommit(oid) | ||
| 359 | + .then(function(testCommit) { | ||
| 360 | + return testCommit.getDiff(); | ||
| 361 | + }) | ||
| 362 | + .then(function(_secondDiff) { | ||
| 363 | + secondDiff = _secondDiff[0]; | ||
| 364 | + return Promise.all([ | ||
| 365 | + getLinesFromDiff(firstDiff), | ||
| 366 | + getLinesFromDiff(secondDiff) | ||
| 367 | + ]); | ||
| 368 | + }) | ||
| 369 | + .then(function(listOfLines) { | ||
| 370 | + linesOfFirstDiff = listOfLines[0]; | ||
| 371 | + linesOfSecondDiff = listOfLines[1]; | ||
| 372 | + return firstDiff.merge(secondDiff); | ||
| 373 | + }) | ||
| 374 | + .then(function() { | ||
| 375 | + return getLinesFromDiff(firstDiff); | ||
| 376 | + }) | ||
| 377 | + .then(function(linesOfMergedDiff) { | ||
| 378 | + var allDiffLines = _.flatten([ | ||
| 379 | + linesOfFirstDiff, | ||
| 380 | + linesOfSecondDiff | ||
| 381 | + ]); | ||
| 382 | + _.forEach(allDiffLines, function(diffLine) { | ||
| 383 | + assert.ok(_.includes(linesOfMergedDiff, diffLine)); | ||
| 384 | + }); | ||
| 385 | + }); | ||
| 386 | + }); | ||
| 387 | + | ||
| 329 | 388 | // This wasn't working before. It was only passing because the promise chain | |
| 330 | 389 | // was broken | |
| 331 | 390 | it.skip("can find similar files in a diff", function() { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments