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
21 changes: 19 additions & 2 deletions generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,21 @@
"index": {
"functions": {
"git_index_add_all": {
"ignore": true
"args": {
"pathspec": {
"isOptional": true
},
"flags": {
"isOptional": true
},
"callback": {
"isOptional": true
}
},
"isAsync": true,
"return": {
"isErrorCode": true
}
},
"git_index_conflict_get": {
"ignore": true
Expand Down Expand Up @@ -780,7 +794,10 @@
}
}
}
}
},
"dependencies": [
"../include/str_array_converter.h"
]
},
"index_entry": {
"ignore": false
Expand Down
4 changes: 2 additions & 2 deletions generate/scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ var Helpers = {
if (Helpers.isCallbackFunction(type)) {
Helpers.processCallback(arg);

var argOverrides = argOverrides.args || {};
var callBackArgOverrides = argOverrides.args || {};
arg.args = arg.args || [];
arg.args.forEach(function (argForCallback) {
Helpers.decorateArg(argForCallback, arg.args, null, null, argOverrides[argForCallback.name] || {}, enums);
Helpers.decorateArg(argForCallback, arg.args, null, null, callBackArgOverrides[argForCallback.name] || {}, enums);
});
}
else if (typeDef && fnDef) {
Expand Down
22 changes: 22 additions & 0 deletions generate/templates/manual/include/str_array_converter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef STR_ARRAY_H
#define STR_ARRAY_H

#include <v8.h>

#include "nan.h"
#include "git2/strarray.h"

using namespace v8;

class StrArrayConverter {
public:

static git_strarray *Convert (Handle<v8::Value> val);

private:
static git_strarray *ConvertArray(Array *val);
static git_strarray *ConvertString(Handle<String> val);
static git_strarray *ConstructStrArray(int argc, char** argv);
};

#endif
61 changes: 61 additions & 0 deletions generate/templates/manual/src/str_array_converter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <nan.h>
#include <node.h>
#include <string>
#include <cstring>

#include "../include/str_array_converter.h"
#include "git2/strarray.h"

using namespace v8;
using namespace node;

git_strarray *StrArrayConverter::Convert(Handle<v8::Value> val) {
if (!val->BooleanValue()) {
return NULL;
}
else if (val->IsArray()) {
return ConvertArray(Array::Cast(*val));
}
else if (val->IsString() || val->IsStringObject()) {
return ConvertString(val->ToString());
}
else {
return NULL;
}
}

git_strarray *StrArrayConverter::ConvertArray(Array *val) {
int count = val->Length();
char **strings = (char **)malloc(sizeof(char*) * count);
git_strarray *result;

for(int i = 0; i < count; i++) {
NanUtf8String entry(val->CloneElementAt(i));
strings[i] = *entry;
}

result = ConstructStrArray(count, strings);
free(strings);
return result;
}

git_strarray* StrArrayConverter::ConvertString(Handle<String> val) {
char *strings[1];
NanUtf8String utf8String(val);

strings[0] = *utf8String;

return ConstructStrArray(1, strings);
}

git_strarray *StrArrayConverter::ConstructStrArray(int argc, char** argv) {
git_strarray *result = (git_strarray *)malloc(sizeof(git_strarray*));
result->count = argc;
result->strings = (char **)malloc(sizeof(char*) * result->count);

for(size_t i = 0; i < result->count; i++) {
result->strings[i] = strdup(argv[i]);
}

return result;
}
10 changes: 8 additions & 2 deletions generate/templates/partials/async_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
{%if arg.isSelf %}
baton->{{ arg.name }} = ObjectWrap::Unwrap<{{ arg.cppClassName }}>(args.This())->GetValue();
{%elsif arg.isCallbackFunction %}
baton->{{ arg.name}} = {{ cppFunctionName }}_{{ arg.name }}_cppCallback;
baton->{{ arg.payload.name }} = new NanCallback(args[{{ arg.jsArg }}].As<Function>());
if (!args[{{ arg.jsArg }}]->IsFunction()) {
baton->{{ arg.name }} = NULL;
baton->{{ arg.payload.name }} = NULL;
}
else {
baton->{{ arg.name}} = {{ cppFunctionName }}_{{ arg.name }}_cppCallback;
baton->{{ arg.payload.name }} = new NanCallback(args[{{ arg.jsArg }}].As<Function>());
}
{%elsif arg.payloadFor %}
{%-- payloads are ignored --%}
{%elsif arg.name %}
Expand Down
8 changes: 7 additions & 1 deletion generate/templates/partials/convert_from_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
{{ cType }} from_{{ name }};
{%if isOptional | or isBoolean %}

{%if cppClassName != 'GitStrarray'%}
if (args[{{ jsArg }}]->Is{{ cppClassName|cppToV8 }}()) {
{%endif%}
{%endif%}
{%if cppClassName == 'String'%}

String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString());
from_{{ name }} = ({{ cType }}) strdup(*{{ name }});
{%elsif cppClassName == 'GitStrarray' %}

from_{{ name }} = StrArrayConverter::Convert(args[{{ jsArg }}]);
{%elsif cppClassName == 'Wrapper'%}

String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString());
Expand Down Expand Up @@ -77,11 +82,12 @@
from_{{ name }} = args[{{ jsArg }}]->IsTrue() ? 1 : 0;
}
{%elsif isOptional %}
{%if cppClassName != 'GitStrarray'%}
}
else {
from_{{ name }} = 0;
}

{%endif%}
{%endif%}
// end convert_from_v8 block
{%endif%}
4 changes: 4 additions & 0 deletions generate/templates/partials/guard_arguments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
{%elsif arg.isCallbackFunction %}
if (args.Length() == {{arg.jsArg}} || !args[{{arg.jsArg}}]->IsFunction()) {
return NanThrowError("{{arg.jsClassName}} {{arg.name}} is required.");
}
{%elsif arg.cppClassName == "GitStrarray" %}
if (args.Length() == {{arg.jsArg}} || !args[{{arg.jsArg}}]->BooleanValue()) {
return NanThrowError("Array, String Object, or string {{arg.name}} is required.");
}
{%else%}
if (args.Length() == {{arg.jsArg}} || !args[{{arg.jsArg}}]->Is{{arg.cppClassName|cppToV8}}()) {
Expand Down
1 change: 1 addition & 0 deletions generate/templates/templates/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"src/nodegit.cc",
"src/wrapper.cc",
"src/functions/copy.cc",
"src/str_array_converter.cc",
{% each %}
{% if type != "enum" %}
"src/{{ name }}.cc",
Expand Down
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ Index.prototype.entries = function() {
return result;
};

var addAll = Index.prototype.addAll;
Index.prototype.addAll = function(pathspec, flags, matchedCallback) {
return addAll.call(this, pathspec, flags, matchedCallback, null);
};

module.exports = Index;
27 changes: 27 additions & 0 deletions test/tests/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
var assert = require("assert");
var path = require("path");
var local = path.join.bind(path, __dirname);
var Promise = require("nodegit-promise");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));

describe("Index", function() {
var Repository = require(local("../../lib/repository"));
Expand Down Expand Up @@ -29,4 +32,28 @@ describe("Index", function() {

assert.equal(entries[0].path(), ".gitignore");
});

it("can add all entries to the index", function() {
var repo = this.repo;
var index = this.index;
var fileContent = {
newFile1: "this has some content",
newFile2: "and this will have more content"
};
var fileNames = Object.keys(fileContent);

return Promise.all(fileNames.map(function(fileName) {
fse.writeFile(path.join(repo.workdir(), fileName), fileContent[fileName]);
}))
.then(function() {
return index.addAll();
})
.then(function() {
var newFiles = index.entries().filter(function(entry) {
return ~fileNames.indexOf(entry.path());
});

assert.equal(newFiles.length, 2);
});
});
});