diff --git a/lib/tree_entry.js b/lib/tree_entry.js index 2e4f15484..d4309098c 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -79,7 +79,8 @@ TreeEntry.prototype.getBlob = function(callback) { * @return {String} */ TreeEntry.prototype.path = function(callback) { - return path.join(this.parent.path(), this.dirtoparent, this.filename()); + var dirtoparent = this.dirtoparent || ""; + return path.join(this.parent.path(), dirtoparent, this.filename()); }; /** diff --git a/test/tests/tree_entry.js b/test/tests/tree_entry.js index bfc32417d..371b8e636 100644 --- a/test/tests/tree_entry.js +++ b/test/tests/tree_entry.js @@ -1,4 +1,5 @@ var assert = require("assert"); +var Promise = require("nodegit-promise"); var path = require("path"); var local = path.join.bind(path, __dirname); @@ -52,6 +53,33 @@ describe("TreeEntry", function() { }); }); + it("provides the full path when the entry came from a tree", function(done) { + var testTree = function(tree, _dir) { + var dir = _dir || "", + testPromises = []; + tree.entries().forEach(function(entry) { + var currentPath = path.join(dir, entry.filename()); + if (entry.isTree()) { + testPromises.push( + entry.getTree().then(function (subtree) { + return testTree(subtree, currentPath); + }) + ); + } else { + assert.equal(entry.path(), currentPath); + } + }); + + return Promise.all(testPromises); + }; + + return this.commit.getTree() + .then(testTree) + .done(function() { + done(); + }); + }); + it("provides the blob representation of the entry", function() { return this.commit.getEntry("test/raw-commit.js") .then(function(entry) {