FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix for issue #591. TreeEntry.path() throws when TreeEntry came from Tree.entries() by tomruggs · Pull Request #592 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 2 additions & 1 deletion lib/tree_entry.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL