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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,28 @@
"jsFunctionName": "entryCount"
},
"git_index_find": {
"ignore": true
"isAsync": true,
"args": {
"at_pos": {
"isReturn": true,
"shouldAlloc": true
}
},
"return": {
"isErrorCode": true
}
},
"git_index_find_prefix": {
"isAsync": true,
"args": {
"at_pos": {
"isReturn": true,
"shouldAlloc": true
}
},
"return": {
"isErrorCode": true
}
},
"git_index_free": {
"ignore": true
Expand Down
64 changes: 64 additions & 0 deletions test/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("Index", function() {
var RepoUtils = require("../utils/repository_setup");
var NodeGit = require("../../");
var Repository = NodeGit.Repository;
var ErrorCodes = NodeGit.Error.CODE;

var reposPath = local("../repos/workdir");

Expand Down Expand Up @@ -359,4 +360,67 @@ describe("Index", function() {
assert(index.hasConflicts());
});
});

it("can find the specified file in the index", function() {
var test = this;

return test.index.find("src/wrapper.cc")
.then(function(position) {
assert.notEqual(position, null);
});
});

it("cannot find the specified file in the index", function() {
var test = this;

return test.index.find("src/thisisfake.cc")
.then(function(position) {
assert.fail("the item should not be found");
})
.catch(function(error) {
assert.strictEqual(error.errno, ErrorCodes.ENOTFOUND);
});
});

it("cannot find the directory in the index", function() {
var test = this;

return test.index.find("src")
.then(function(position) {
assert.fail("the item should not be found");
})
.catch(function(error) {
assert.strictEqual(error.errno, ErrorCodes.ENOTFOUND);
});
});

it("can find the specified prefix in the index", function() {
var test = this;

return test.index.findPrefix("src/")
.then(function(position) {
assert.notEqual(position, null);
});
});

it("cannot find the specified prefix in the index", function() {
var test = this;

return test.index.find("testing123/")
.then(function(position) {
assert.fail("the item should not be found");
})
.catch(function(error) {
assert.strictEqual(error.errno, ErrorCodes.ENOTFOUND);
});
});

it("can find the prefix when a file shares the name", function() {
var test = this;

return test.index.find("LICENSE")
.then(function(position) {
assert.notEqual(position, null);
});
});
});