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
3 changes: 2 additions & 1 deletion lib/tree_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
};

/**
Expand Down
28 changes: 28 additions & 0 deletions test/tests/tree_entry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var assert = require("assert");
var Promise = require("nodegit-promise");
var path = require("path");
var local = path.join.bind(path, __dirname);

Expand Down Expand Up @@ -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) {
Expand Down