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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/include/
/lib/enums.js
/lib/nodegit.js
/coverage/


/vendor/Release
Expand Down
6 changes: 6 additions & 0 deletions generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@
},
"git_diff_tree_to_tree": {
"args": {
"old_tree": {
"isOptional": true
},
"new_tree": {
"isOptional": true
},
"opts": {
"isOptional": true
}
Expand Down
21 changes: 13 additions & 8 deletions lib/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,21 @@ Commit.prototype.parents = function() {
Commit.prototype.getDiff = function(callback) {
var commit = this;

return commit.getParents().then(function(parents) {
var diffs = parents.map(function(parent) {
return parent.getTree().then(function(parentTree) {
return commit.getTree().then(function(thisTree) {
return thisTree.diff(parentTree);
return commit.getTree().then(function(thisTree) {
return commit.getParents().then(function(parents) {
var diffs;
if (parents.length) {
diffs = parents.map(function(parent) {
return parent.getTree().then(function(parentTree) {
return thisTree.diff(parentTree);
});
});
});
});
} else {
diffs = [thisTree.diff(null)];
}

return Promise.all(diffs);
return Promise.all(diffs);
});
}).then(function(diffs) {
if (typeof callback === "function") {
callback(null, diffs);
Expand Down
18 changes: 18 additions & 0 deletions test/tests/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,22 @@ describe("Diff", function() {
"1 line\n"
);
});

it("can diff with a null tree", function() {
var repo = this.repository;
var tree = this.masterCommitTree;
return Diff.treeToTree(repo, null, tree, null).then(function(diff) {
assert.equal(diff.patches().length, 85);
});
});

it("can diff the initial commit of a repository", function() {
var repo = this.repository;
var oid = "99c88fd2ac9c5e385bd1fe119d89c83dce326219"; // First commit
return repo.getCommit(oid).then(function(commit) {
return commit.getDiff().then(function(diffs) {
assert.equal(diffs[0].patches().length, 8);
});
});
});
});