Fix TreeEntry.entryById and .getEntry · nodegit/nodegit@409ebb3 · GitHub
Skip to content

Commit 409ebb3

Browse files
committed
Fix TreeEntry.entryById and .getEntry
* entryById now follows pattern of entryByName and entryByIndex where the parent property is added to the entry. * entryByPath renamed to _entryByPath since getEntry should be used instead. * Simple test for entryById added. * Setup of commits used in test for TreeEntry.walk moved to test setup so getEntry can test searching by path as well.
1 parent 1047f66 commit 409ebb3

3 files changed

Lines changed: 41 additions & 11 deletions

File tree

generate/input/descriptor.json

Lines changed: 2 additions & 0 deletions

lib/tree.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ Tree.prototype.entries = function() {
7373
return result;
7474
};
7575

76+
/**
77+
* Get an entry by oid (does not search subtrees).
78+
*
79+
* @param {String|Oid} id sha or Oid
80+
* @return {TreeEntry}
81+
*/
82+
Tree.prototype.entryById = function(id) {
83+
var entry = this._entryById(id);
84+
entry.parent = this;
85+
return entry;
86+
};
87+
7688
/**
7789
* Get an entry at the ith position.
7890
*
@@ -107,7 +119,7 @@ Tree.prototype.entryByName = function(name) {
107119
Tree.prototype.getEntry = function(filePath, callback) {
108120
var tree = this;
109121

110-
return this.entryByPath(filePath).then(function(entry) {
122+
return this._entryByPath(filePath).then(function(entry) {
111123
entry.parent = tree;
112124
entry.dirtoparent = path.dirname(filePath);
113125

test/tests/tree.js

Lines changed: 26 additions & 10 deletions

0 commit comments

Comments
 (0)