Skip to content

Commit c7f86de

Browse files
committed
Fix path function in tree_entry
If the entry path goes beyond the immediate children (a file in a subdir for instance) then path would return a path missing the subdir name
1 parent 84901cd commit c7f86de

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/tree.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var pathmod = require("path");
12
var events = require("events");
23
var NodeGit = require("../");
34
var Diff = NodeGit.Diff;
@@ -69,6 +70,7 @@ Tree.prototype.getEntry = function(path, callback) {
6970

7071
return this.entryByPath(path).then(function(entry) {
7172
entry.parent = tree;
73+
entry.dirtoparent = pathmod.dirname(path);
7274

7375
if (typeof callback === "function") {
7476
callback(null, entry);

lib/tree_entry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ TreeEntry.prototype.getBlob = function(callback) {
7979
* @return {String}
8080
*/
8181
TreeEntry.prototype.path = function(callback) {
82-
return path.join(this.parent.path(), this.filename());
82+
return path.join(this.parent.path(), this.dirtoparent, this.filename());
8383
};
8484

8585
/**

test/tests/tree_entry.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ describe("TreeEntry", function() {
4545
});
4646
});
4747

48+
it("provides the full path", function() {
49+
return this.commit.getEntry("test/raw-commit.js")
50+
.then(function(entry) {
51+
assert.equal(entry.path(), "test/raw-commit.js");
52+
});
53+
});
54+
4855
it("provides the blob representation of the entry", function() {
4956
return this.commit.getEntry("test/raw-commit.js")
5057
.then(function(entry) {

0 commit comments

Comments
 (0)