Skip to content

Commit 826e548

Browse files
authored
Merge pull request nodegit#1704 from henkesn/treeupdate
Fix Tree#createUpdated
2 parents af6e69e + 16e29c9 commit 826e548

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

generate/input/descriptor.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4187,6 +4187,16 @@
41874187
"singletonCppClassName": "GitRepository"
41884188
},
41894189
"functions": {
4190+
"git_tree_create_updated": {
4191+
"args": {
4192+
"updates": {
4193+
"cType": "git_tree_update *",
4194+
"cppClassName": "Array",
4195+
"jsClassName": "Array",
4196+
"arrayElementCppClassName": "GitTreeUpdate"
4197+
}
4198+
}
4199+
},
41904200
"git_tree_entry_byid": {
41914201
"return": {
41924202
"ownedByThis": true
@@ -4361,6 +4371,10 @@
43614371
"../include/git_buf_converter.h"
43624372
]
43634373
},
4374+
"tree_update": {
4375+
"hasConstructor": true,
4376+
"ignoreInit": true
4377+
},
43644378
"writestream": {
43654379
"cType": "git_writestream",
43664380
"needsForwardDeclaration": false,

generate/templates/partials/convert_from_v8.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@
4848
{%elsif cppClassName == 'Array'%}
4949

5050
v8::Local<v8::Array> tmp_{{ name }} = v8::Local<v8::Array>::Cast(info[{{ jsArg }}]);
51-
from_{{ name }} = ({{ cType }})malloc(tmp_{{ name }}->Length() * sizeof({{ cType|replace '**' '*' }}));
51+
from_{{ name }} = ({{ cType }})malloc(tmp_{{ name }}->Length() * sizeof({{ cType|unPointer }}));
5252
for (unsigned int i = 0; i < tmp_{{ name }}->Length(); i++) {
5353
{%--
5454
// FIXME: should recursively call convertFromv8.
5555
--%}
56-
from_{{ name }}[i] = Nan::ObjectWrap::Unwrap<{{ arrayElementCppClassName }}>(Nan::To<v8::Object>(Nan::Get(tmp_{{ name }}, Nan::New(static_cast<double>(i))).ToLocalChecked()).ToLocalChecked())->GetValue();
56+
from_{{ name }}[i] = {%if not cType|isDoublePointer %}*{%endif%}Nan::ObjectWrap::Unwrap<{{ arrayElementCppClassName }}>(Nan::To<v8::Object>(Nan::Get(tmp_{{ name }}, Nan::New(static_cast<double>(i))).ToLocalChecked()).ToLocalChecked())->GetValue();
5757
}
5858
{%elsif cppClassName == 'Function'%}
5959
{%elsif cppClassName == 'Buffer'%}

test/tests/tree.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ describe("Tree", function() {
3838
}).done(done);
3939
});
4040

41+
it("updates a tree", function () {
42+
var repo = this.existingRepo;
43+
var update = new NodeGit.TreeUpdate();
44+
update.action = NodeGit.Tree.UPDATE.REMOVE;
45+
update.path = "README.md";
46+
return this.commit.getTree().then(function(tree) {
47+
return tree.createUpdated(repo, 1, [update]);
48+
})
49+
.then(function(treeOid) {
50+
return repo.getTree(treeOid);
51+
})
52+
.then(function(updatedTree) {
53+
assert.throws(function () {
54+
updatedTree.entryByName("README.md");
55+
});
56+
});
57+
});
58+
4159
it("walks its entries and returns the same entries on both progress and end",
4260
function() {
4361
var repo = this.repository;

0 commit comments

Comments
 (0)