Skip to content

Commit 9d04b12

Browse files
committed
Update commit.getDiff to handle no parents
#noparents
1 parent 6ea5688 commit 9d04b12

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

lib/commit.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,21 @@ Commit.prototype.parents = function() {
169169
Commit.prototype.getDiff = function(callback) {
170170
var commit = this;
171171

172-
return commit.getParents().then(function(parents) {
173-
var diffs = parents.map(function(parent) {
174-
return parent.getTree().then(function(parentTree) {
175-
return commit.getTree().then(function(thisTree) {
176-
return thisTree.diff(parentTree);
172+
return commit.getTree().then(function(thisTree) {
173+
return commit.getParents().then(function(parents) {
174+
var diffs;
175+
if (parents.length) {
176+
diffs = parents.map(function(parent) {
177+
return parent.getTree().then(function(parentTree) {
178+
return thisTree.diff(parentTree);
179+
});
177180
});
178-
});
179-
});
181+
} else {
182+
diffs = [thisTree.diff(null)];
183+
}
180184

181-
return Promise.all(diffs);
185+
return Promise.all(diffs);
186+
});
182187
}).then(function(diffs) {
183188
if (typeof callback === "function") {
184189
callback(null, diffs);

0 commit comments

Comments
 (0)