FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added git_diff_merge by smith-kyle · Pull Request #1000 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (1) .json  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 9 additions & 1 deletion generate/input/descriptor.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,15 @@
"ignore": true
},
"git_diff_merge": {
"ignore": true
"isAsync": true,
"args": {
"onto": {
"isSelf": true
}
},
"return": {
"isErrorCode": true
}
},
"git_diff_num_deltas_of_type": {
"ignore": true
Expand Down
61 changes: 60 additions & 1 deletion test/tests/diff.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
var assert = require("assert");
var path = require("path");
var promisify = require("promisify-node");
var _ = require("lodash");
var fse = promisify(require("fs-extra"));
var local = path.join.bind(path, __dirname);

function getLinesFromDiff(diff) {
return diff.patches()
.then(function(patches) {
return Promise.all(_.map(patches, function(patch) {
return patch.hunks();
}));
})
.then(function(listsOfHunks) {
var hunks = _.flatten(listsOfHunks);
return Promise.all(_.map(hunks, function(hunk) {
return hunk.lines();
}));
})
.then(function(listsOfLines) {
var lines = _.flatten(listsOfLines);
return _.map(lines, function(line) {
return line.content();
});
});
}

describe("Diff", function() {
var NodeGit = require("../../");
var Repository = NodeGit.Repository;
Expand Down Expand Up @@ -144,7 +166,7 @@ describe("Diff", function() {
});
});

it("can resolve individual line chages from the patch hunks", function() {
it("can resolve individual line changes from the patch hunks", function() {
return this.workdirDiff.patches()
.then(function(patches) {
var result = [];
Expand Down Expand Up @@ -326,6 +348,43 @@ describe("Diff", function() {
});
});


it("can merge two diffs", function() {
var linesOfFirstDiff;
var linesOfSecondDiff;
var firstDiff = this.diff[0];
var secondDiff;
var oid = "c88d39e70585199425b111c6a2c7fa7b4bc617ad";
return this.repository.getCommit(oid)
.then(function(testCommit) {
return testCommit.getDiff();
})
.then(function(_secondDiff) {
secondDiff = _secondDiff[0];
return Promise.all([
getLinesFromDiff(firstDiff),
getLinesFromDiff(secondDiff)
]);
})
.then(function(listOfLines) {
linesOfFirstDiff = listOfLines[0];
linesOfSecondDiff = listOfLines[1];
return firstDiff.merge(secondDiff);
})
.then(function() {
return getLinesFromDiff(firstDiff);
})
.then(function(linesOfMergedDiff) {
var allDiffLines = _.flatten([
linesOfFirstDiff,
linesOfSecondDiff
]);
_.forEach(allDiffLines, function(diffLine) {
assert.ok(_.includes(linesOfMergedDiff, diffLine));
});
});
});

// This wasn't working before. It was only passing because the promise chain
// was broken
it.skip("can find similar files in a diff", function() {
Expand Down

Back | FazBrowse Home | New Git URL