Skip to content

Commit 6cf888f

Browse files
committed
Merge pull request #592 from tomruggs/master
Fix for issue #591. TreeEntry.path() throws when TreeEntry came from Tree.entries()
2 parents f523b6b + 2434c75 commit 6cf888f

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/tree_entry.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ TreeEntry.prototype.getBlob = function(callback) {
7979
* @return {String}
8080
*/
8181
TreeEntry.prototype.path = function(callback) {
82-
return path.join(this.parent.path(), this.dirtoparent, this.filename());
82+
var dirtoparent = this.dirtoparent || "";
83+
return path.join(this.parent.path(), dirtoparent, this.filename());
8384
};
8485

8586
/**

test/tests/tree_entry.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var assert = require("assert");
2+
var Promise = require("nodegit-promise");
23
var path = require("path");
34
var local = path.join.bind(path, __dirname);
45

@@ -52,6 +53,33 @@ describe("TreeEntry", function() {
5253
});
5354
});
5455

56+
it("provides the full path when the entry came from a tree", function(done) {
57+
var testTree = function(tree, _dir) {
58+
var dir = _dir || "",
59+
testPromises = [];
60+
tree.entries().forEach(function(entry) {
61+
var currentPath = path.join(dir, entry.filename());
62+
if (entry.isTree()) {
63+
testPromises.push(
64+
entry.getTree().then(function (subtree) {
65+
return testTree(subtree, currentPath);
66+
})
67+
);
68+
} else {
69+
assert.equal(entry.path(), currentPath);
70+
}
71+
});
72+
73+
return Promise.all(testPromises);
74+
};
75+
76+
return this.commit.getTree()
77+
.then(testTree)
78+
.done(function() {
79+
done();
80+
});
81+
});
82+
5583
it("provides the blob representation of the entry", function() {
5684
return this.commit.getEntry("test/raw-commit.js")
5785
.then(function(entry) {

0 commit comments

Comments
 (0)