diff --git a/lib/tree.js b/lib/tree.js index e632d1337..d7e14d0dc 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -1,3 +1,4 @@ +var path = require("path"); var events = require("events"); var NodeGit = require("../"); var Diff = NodeGit.Diff; @@ -61,14 +62,15 @@ Tree.prototype.entryByName = function(name) { * Get an entry at a path. Unlike by name, this takes a fully * qualified path, like `/foo/bar/baz.javascript` * - * @param {String} path + * @param {String} filePath * @return {TreeEntry} */ -Tree.prototype.getEntry = function(path, callback) { +Tree.prototype.getEntry = function(filePath, callback) { var tree = this; - return this.entryByPath(path).then(function(entry) { + return this.entryByPath(filePath).then(function(entry) { entry.parent = tree; + entry.dirtoparent = path.dirname(filePath); if (typeof callback === "function") { callback(null, entry); diff --git a/lib/tree_entry.js b/lib/tree_entry.js index a2d19def2..2e4f15484 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -79,7 +79,7 @@ TreeEntry.prototype.getBlob = function(callback) { * @return {String} */ TreeEntry.prototype.path = function(callback) { - return path.join(this.parent.path(), this.filename()); + return path.join(this.parent.path(), this.dirtoparent, this.filename()); }; /** diff --git a/test/tests/tree_entry.js b/test/tests/tree_entry.js index 2e0620040..d8769cbd9 100644 --- a/test/tests/tree_entry.js +++ b/test/tests/tree_entry.js @@ -45,6 +45,13 @@ describe("TreeEntry", function() { }); }); + it("provides the full path", function() { + return this.commit.getEntry("test/raw-commit.js") + .then(function(entry) { + assert.equal(entry.path(), "test/raw-commit.js"); + }); + }); + it("provides the blob representation of the entry", function() { return this.commit.getEntry("test/raw-commit.js") .then(function(entry) {