Permalink
Browse files

Added tests for git_attr

  • Loading branch information...
1 parent 568e664 commit 0afd7b544dd2486238f2de7883fe595daa940bed @tbranyen tbranyen committed Jul 18, 2014
Showing with 92 additions and 45 deletions.
  1. +6 −5 generate/descriptor.json
  2. +2 −1 generate/setup.js
  3. +0 −2 generate/templates/asyncFunction.cc.ejs
  4. +36 −36 generate/types.json
  5. +8 −0 lib/attr.js
  6. +1 −1 lib/nodegit.js
  7. +39 −0 test/tests/attr.js
View
11 generate/descriptor.json
@@ -3,11 +3,12 @@
"cType": null,
"functions": {
- "git_attr_get": {
- "ignore": false
+ "git_attr_add_macro": {
+ "ignore": false,
+ "isConstructorMethod": true
},
- "git_attr_get_many": {
+ "git_attr_cache_flush": {
"ignore": false
},
@@ -18,11 +19,11 @@
}
},
- "git_attr_cache_flush": {
+ "git_attr_get": {
"ignore": false
},
- "git_attr_add_macro": {
+ "git_attr_get_many": {
"ignore": false
}
}
View
3 generate/setup.js
@@ -75,6 +75,7 @@ fileNames.forEach(function(fileName, index) {
// Constants.
file.filename = fileName + ".h";
file.ignore = typeof file.ignore == "boolean" ? file.ignore : false;
+ //FIXME
file.cppClassName = "Git" + titleCase(fileName);
file.jsClassName = file.cppClassName;
@@ -193,7 +194,7 @@ fileNames.forEach(function(fileName, index) {
var funcDescriptor = libgit2.functions[functionName];
var descriptor = {};
- var cType = file.cType || "git";
+ var cType = file.cType || "git_" + file.filename.slice(0, -2);
// From the hand maintained file.
var functionDescriptor = functions ? functions[functionName] || ident : ident;
View
2 generate/templates/asyncFunction.cc.ejs
@@ -1,5 +1,3 @@
-#include "../include/functions/copy.h"
-
/**
<% include doc.cc.ejs -%>
*/
View
72 generate/types.json
@@ -1,7 +1,7 @@
{
"git_attr_get": {
- "cpp": "AttrGet",
- "js": "attrGet"
+ "cpp": "Get",
+ "js": "get"
},
"const char **": {
"js": "String",
@@ -24,16 +24,16 @@
"cpp": "Number"
},
"git_attr_get_many": {
- "cpp": "AttrGetMany",
- "js": "attrGetMany"
+ "cpp": "GetMany",
+ "js": "getMany"
},
"size_t": {
"js": "Number",
"cpp": "Uint32"
},
"git_attr_foreach": {
- "cpp": "AttrForeach",
- "js": "attrForeach"
+ "cpp": "Foreach",
+ "js": "foreach"
},
"git_attr_foreach_cb": {
"js": "AttrForeachCb",
@@ -44,16 +44,16 @@
"cpp": "void"
},
"git_attr_cache_flush": {
- "cpp": "AttrCacheFlush",
- "js": "attrCacheFlush"
+ "cpp": "CacheFlush",
+ "js": "cacheFlush"
},
"void": {
"js": "void",
"cpp": "void"
},
"git_attr_add_macro": {
- "cpp": "AttrAddMacro",
- "js": "attrAddMacro"
+ "cpp": "AddMacro",
+ "js": "addMacro"
},
"git_blob_free": {
"cpp": "Free",
@@ -2376,8 +2376,8 @@
"js": "peel"
},
"git_threads_init": {
- "cpp": "ThreadsInit",
- "js": "threadsInit"
+ "cpp": "Init",
+ "js": "init"
},
"git_threads_shutdown": {
"cpp": "ThreadsShutdown",
@@ -2617,44 +2617,44 @@
"js": "Attr"
},
"git_attr_get *": {
- "cpp": "AttrGet",
- "js": "attrGet"
+ "cpp": "Get",
+ "js": "get"
},
"const git_attr_get *": {
- "cpp": "AttrGet",
- "js": "attrGet"
+ "cpp": "Get",
+ "js": "get"
},
"git_attr_get_many *": {
- "cpp": "AttrGetMany",
- "js": "attrGetMany"
+ "cpp": "GetMany",
+ "js": "getMany"
},
"const git_attr_get_many *": {
- "cpp": "AttrGetMany",
- "js": "attrGetMany"
+ "cpp": "GetMany",
+ "js": "getMany"
},
"git_attr_foreach *": {
- "cpp": "AttrForeach",
- "js": "attrForeach"
+ "cpp": "Foreach",
+ "js": "foreach"
},
"const git_attr_foreach *": {
- "cpp": "AttrForeach",
- "js": "attrForeach"
+ "cpp": "Foreach",
+ "js": "foreach"
},
"git_attr_cache_flush *": {
- "cpp": "AttrCacheFlush",
- "js": "attrCacheFlush"
+ "cpp": "CacheFlush",
+ "js": "cacheFlush"
},
"const git_attr_cache_flush *": {
- "cpp": "AttrCacheFlush",
- "js": "attrCacheFlush"
+ "cpp": "CacheFlush",
+ "js": "cacheFlush"
},
"git_attr_add_macro *": {
- "cpp": "AttrAddMacro",
- "js": "attrAddMacro"
+ "cpp": "AddMacro",
+ "js": "addMacro"
},
"const git_attr_add_macro *": {
- "cpp": "AttrAddMacro",
- "js": "attrAddMacro"
+ "cpp": "AddMacro",
+ "js": "addMacro"
},
"git_blame": {
"cpp": "GitBlame",
@@ -8513,12 +8513,12 @@
"js": "peel"
},
"git_threads_init *": {
- "cpp": "ThreadsInit",
- "js": "threadsInit"
+ "cpp": "Init",
+ "js": "init"
},
"const git_threads_init *": {
- "cpp": "ThreadsInit",
- "js": "threadsInit"
+ "cpp": "Init",
+ "js": "init"
},
"git_threads_shutdown *": {
"cpp": "ThreadsShutdown",
View
8 lib/attr.js
@@ -2,4 +2,12 @@ var NodeGit = require("../");
var Attr = NodeGit.Attr;
+Attr.Check = {
+ FILE_THEN_INDEX: 0,
+ INDEX_THEN_FILE: 1,
+ INDEX_ONLY: 2,
+
+ NO_SYSTEM: 1 << 2
+};
+
module.exports = Attr;
View
2 lib/nodegit.js
@@ -59,4 +59,4 @@ promisify(exports);
exports.version = require("../package").version;
// Initialize threads.
-exports.Threads.threadsInit();
+exports.Threads.init();
View
39 test/tests/attr.js
@@ -0,0 +1,39 @@
+var assert = require("assert");
+var path = require("path");
+
+describe("Blob", function() {
+ var reposPath = path.resolve("test/repos/workdir/.git");
+
+ var Repository = require("../../lib/repository");
+ var Attr = require("../../lib/attr");
+
+ before(function() {
+ var test = this;
+
+ return Repository.open(reposPath).then(function(repository) {
+ test.repository = repository;
+ });
+ });
+
+ it("can add a macro definition", function() {
+ var error = Attr.addMacro(this.repository, "binary", "-diff -crlf");
+
+ assert.equal(error, 0);
+ });
+
+ it("can flush the attr cache", function() {
+ Attr.cacheFlush(this.repository);
+ });
+
+ // FIXME Currently segfaults.
+ it.skip("can lookup the value of a git attribute", function() {
+ var flags = Attr.Check.NO_SYSTEM;
+ var getAttr = Attr.get(this.repository, flags, ".gitattributes", "test");
+
+ return getAttr.then(function(val) {
+ console.log(val);
+ }).catch(function(ex) {
+ console.log(ex);
+ });
+ });
+});

0 comments on commit 0afd7b5

Please sign in to comment.