Skip to content

Commit 63f835e

Browse files
committed
fix Tree#entryByName function and add test
1 parent 84c4335 commit 63f835e

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

generate/input/descriptor.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,9 +2499,7 @@
24992499
"jsFunctionName": "_entryByIndex"
25002500
},
25012501
"git_tree_entry_byname": {
2502-
"return": {
2503-
"ownedByThis": true
2504-
}
2502+
"jsFunctionName": "_entryByName"
25052503
},
25062504
"git_tree_entrycount": {
25072505
"jsFunctionName": "entryCount"

lib/tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Tree.prototype.entryByIndex = function(i) {
6565
* @return {TreeEntry}
6666
*/
6767
Tree.prototype.entryByName = function(name) {
68-
var entry = this.entryByName(name);
68+
var entry = this._entryByName(name);
6969
entry.parent = this;
7070
return entry;
7171
};

test/tests/tree.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,40 @@ var promisify = require("promisify-node");
55
var fse = promisify(require("fs-extra"));
66

77
describe("Tree", function() {
8+
var NodeGit = require("../../");
89
var RepoUtils = require("../utils/repository_setup");
910

1011
var repoPath = local("../repos/tree");
12+
var existingPath = local("../repos/workdir");
13+
var oid = "5716e9757886eaf38d51c86b192258c960d9cfea";
1114

1215
beforeEach(function() {
1316
var test = this;
1417
return RepoUtils.createRepository(repoPath)
1518
.then(function(repo) {
1619
test.repository = repo;
20+
}).then(function() {
21+
return NodeGit.Repository.open(existingPath);
22+
}).then(function(repository) {
23+
test.existingRepo = repository;
24+
return repository.getCommit(oid);
25+
}).then(function(commit) {
26+
test.commit = commit;
1727
});
1828
});
1929

2030
after(function() {
2131
return fse.remove(repoPath);
2232
});
2333

34+
it("gets an entry by name",
35+
function(done) {
36+
this.commit.getTree().then(function(tree) {
37+
var entry = tree.entryByName("README.md");
38+
assert(entry);
39+
}).done(done);
40+
});
41+
2442
it("walks its entries and returns the same entries on both progress and end",
2543
function() {
2644
var repo = this.repository;

0 commit comments

Comments
 (0)