Skip to content

Commit 0afd7b5

Browse files
committed
Added tests for git_attr
1 parent 568e664 commit 0afd7b5

File tree

7 files changed

+92
-45
lines changed

7 files changed

+92
-45
lines changed

generate/descriptor.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"cType": null,
44

55
"functions": {
6-
"git_attr_get": {
7-
"ignore": false
6+
"git_attr_add_macro": {
7+
"ignore": false,
8+
"isConstructorMethod": true
89
},
910

10-
"git_attr_get_many": {
11+
"git_attr_cache_flush": {
1112
"ignore": false
1213
},
1314

@@ -18,11 +19,11 @@
1819
}
1920
},
2021

21-
"git_attr_cache_flush": {
22+
"git_attr_get": {
2223
"ignore": false
2324
},
2425

25-
"git_attr_add_macro": {
26+
"git_attr_get_many": {
2627
"ignore": false
2728
}
2829
}

generate/setup.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ fileNames.forEach(function(fileName, index) {
7575
// Constants.
7676
file.filename = fileName + ".h";
7777
file.ignore = typeof file.ignore == "boolean" ? file.ignore : false;
78+
//FIXME
7879
file.cppClassName = "Git" + titleCase(fileName);
7980
file.jsClassName = file.cppClassName;
8081

@@ -193,7 +194,7 @@ fileNames.forEach(function(fileName, index) {
193194

194195
var funcDescriptor = libgit2.functions[functionName];
195196
var descriptor = {};
196-
var cType = file.cType || "git";
197+
var cType = file.cType || "git_" + file.filename.slice(0, -2);
197198

198199
// From the hand maintained file.
199200
var functionDescriptor = functions ? functions[functionName] || ident : ident;

generate/templates/asyncFunction.cc.ejs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include "../include/functions/copy.h"
2-
31
/**
42
<% include doc.cc.ejs -%>
53
*/

generate/types.json

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"git_attr_get": {
3-
"cpp": "AttrGet",
4-
"js": "attrGet"
3+
"cpp": "Get",
4+
"js": "get"
55
},
66
"const char **": {
77
"js": "String",
@@ -24,16 +24,16 @@
2424
"cpp": "Number"
2525
},
2626
"git_attr_get_many": {
27-
"cpp": "AttrGetMany",
28-
"js": "attrGetMany"
27+
"cpp": "GetMany",
28+
"js": "getMany"
2929
},
3030
"size_t": {
3131
"js": "Number",
3232
"cpp": "Uint32"
3333
},
3434
"git_attr_foreach": {
35-
"cpp": "AttrForeach",
36-
"js": "attrForeach"
35+
"cpp": "Foreach",
36+
"js": "foreach"
3737
},
3838
"git_attr_foreach_cb": {
3939
"js": "AttrForeachCb",
@@ -44,16 +44,16 @@
4444
"cpp": "void"
4545
},
4646
"git_attr_cache_flush": {
47-
"cpp": "AttrCacheFlush",
48-
"js": "attrCacheFlush"
47+
"cpp": "CacheFlush",
48+
"js": "cacheFlush"
4949
},
5050
"void": {
5151
"js": "void",
5252
"cpp": "void"
5353
},
5454
"git_attr_add_macro": {
55-
"cpp": "AttrAddMacro",
56-
"js": "attrAddMacro"
55+
"cpp": "AddMacro",
56+
"js": "addMacro"
5757
},
5858
"git_blob_free": {
5959
"cpp": "Free",
@@ -2376,8 +2376,8 @@
23762376
"js": "peel"
23772377
},
23782378
"git_threads_init": {
2379-
"cpp": "ThreadsInit",
2380-
"js": "threadsInit"
2379+
"cpp": "Init",
2380+
"js": "init"
23812381
},
23822382
"git_threads_shutdown": {
23832383
"cpp": "ThreadsShutdown",
@@ -2617,44 +2617,44 @@
26172617
"js": "Attr"
26182618
},
26192619
"git_attr_get *": {
2620-
"cpp": "AttrGet",
2621-
"js": "attrGet"
2620+
"cpp": "Get",
2621+
"js": "get"
26222622
},
26232623
"const git_attr_get *": {
2624-
"cpp": "AttrGet",
2625-
"js": "attrGet"
2624+
"cpp": "Get",
2625+
"js": "get"
26262626
},
26272627
"git_attr_get_many *": {
2628-
"cpp": "AttrGetMany",
2629-
"js": "attrGetMany"
2628+
"cpp": "GetMany",
2629+
"js": "getMany"
26302630
},
26312631
"const git_attr_get_many *": {
2632-
"cpp": "AttrGetMany",
2633-
"js": "attrGetMany"
2632+
"cpp": "GetMany",
2633+
"js": "getMany"
26342634
},
26352635
"git_attr_foreach *": {
2636-
"cpp": "AttrForeach",
2637-
"js": "attrForeach"
2636+
"cpp": "Foreach",
2637+
"js": "foreach"
26382638
},
26392639
"const git_attr_foreach *": {
2640-
"cpp": "AttrForeach",
2641-
"js": "attrForeach"
2640+
"cpp": "Foreach",
2641+
"js": "foreach"
26422642
},
26432643
"git_attr_cache_flush *": {
2644-
"cpp": "AttrCacheFlush",
2645-
"js": "attrCacheFlush"
2644+
"cpp": "CacheFlush",
2645+
"js": "cacheFlush"
26462646
},
26472647
"const git_attr_cache_flush *": {
2648-
"cpp": "AttrCacheFlush",
2649-
"js": "attrCacheFlush"
2648+
"cpp": "CacheFlush",
2649+
"js": "cacheFlush"
26502650
},
26512651
"git_attr_add_macro *": {
2652-
"cpp": "AttrAddMacro",
2653-
"js": "attrAddMacro"
2652+
"cpp": "AddMacro",
2653+
"js": "addMacro"
26542654
},
26552655
"const git_attr_add_macro *": {
2656-
"cpp": "AttrAddMacro",
2657-
"js": "attrAddMacro"
2656+
"cpp": "AddMacro",
2657+
"js": "addMacro"
26582658
},
26592659
"git_blame": {
26602660
"cpp": "GitBlame",
@@ -8513,12 +8513,12 @@
85138513
"js": "peel"
85148514
},
85158515
"git_threads_init *": {
8516-
"cpp": "ThreadsInit",
8517-
"js": "threadsInit"
8516+
"cpp": "Init",
8517+
"js": "init"
85188518
},
85198519
"const git_threads_init *": {
8520-
"cpp": "ThreadsInit",
8521-
"js": "threadsInit"
8520+
"cpp": "Init",
8521+
"js": "init"
85228522
},
85238523
"git_threads_shutdown *": {
85248524
"cpp": "ThreadsShutdown",

lib/attr.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@ var NodeGit = require("../");
22

33
var Attr = NodeGit.Attr;
44

5+
Attr.Check = {
6+
FILE_THEN_INDEX: 0,
7+
INDEX_THEN_FILE: 1,
8+
INDEX_ONLY: 2,
9+
10+
NO_SYSTEM: 1 << 2
11+
};
12+
513
module.exports = Attr;

lib/nodegit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ promisify(exports);
5959
exports.version = require("../package").version;
6060

6161
// Initialize threads.
62-
exports.Threads.threadsInit();
62+
exports.Threads.init();

test/tests/attr.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var assert = require("assert");
2+
var path = require("path");
3+
4+
describe("Blob", function() {
5+
var reposPath = path.resolve("test/repos/workdir/.git");
6+
7+
var Repository = require("../../lib/repository");
8+
var Attr = require("../../lib/attr");
9+
10+
before(function() {
11+
var test = this;
12+
13+
return Repository.open(reposPath).then(function(repository) {
14+
test.repository = repository;
15+
});
16+
});
17+
18+
it("can add a macro definition", function() {
19+
var error = Attr.addMacro(this.repository, "binary", "-diff -crlf");
20+
21+
assert.equal(error, 0);
22+
});
23+
24+
it("can flush the attr cache", function() {
25+
Attr.cacheFlush(this.repository);
26+
});
27+
28+
// FIXME Currently segfaults.
29+
it.skip("can lookup the value of a git attribute", function() {
30+
var flags = Attr.Check.NO_SYSTEM;
31+
var getAttr = Attr.get(this.repository, flags, ".gitattributes", "test");
32+
33+
return getAttr.then(function(val) {
34+
console.log(val);
35+
}).catch(function(ex) {
36+
console.log(ex);
37+
});
38+
});
39+
});

0 commit comments

Comments
 (0)