Skip to content

Commit 540818e

Browse files
committed
Expose git_push_negotiation Callback
1 parent 4b11a46 commit 540818e

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

generate/input/callbacks.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,30 @@
948948
"throttle": 100
949949
}
950950
},
951+
"git_push_negotiation": {
952+
"args": [
953+
{
954+
"name": "updates",
955+
"type": "const git_push_update **"
956+
},
957+
{
958+
"name": "len",
959+
"type": "size_t"
960+
},
961+
{
962+
"name": "payload",
963+
"type": "void *"
964+
}
965+
],
966+
"return": {
967+
"type": "int",
968+
"noResults": 0,
969+
"success": 0,
970+
"error": -1,
971+
"cancel": -1,
972+
"throttle": 100
973+
}
974+
},
951975
"git_transport_cb": {
952976
"args": [
953977
{

generate/input/descriptor.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3605,7 +3605,24 @@
36053605
"ignore": true
36063606
},
36073607
"push_negotiation": {
3608-
"ignore": true
3608+
"args": [
3609+
{
3610+
"name": "updates",
3611+
"cType": "const git_push_update **",
3612+
"cppClassName": "Array",
3613+
"jsClassName": "Array",
3614+
"arrayElementCppClassName": "GitPushUpdate",
3615+
"arrayLengthArgumentName": "len"
3616+
},
3617+
{
3618+
"name": "len",
3619+
"ctype": "size_t"
3620+
},
3621+
{
3622+
"name": "payload",
3623+
"ctype": "void *"
3624+
}
3625+
]
36093626
},
36103627
"sideband_progress": {
36113628
"ignore": false

generate/input/libgit2-supplement.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,11 @@
16671667
"type": "git_push_update_reference_cb",
16681668
"name": "push_update_reference"
16691669
},
1670+
{
1671+
"type": "git_push_negotiation",
1672+
"name": "push_negotiation",
1673+
"isCallback": true
1674+
},
16701675
{
16711676
"type": "void *",
16721677
"name": "payload"

test/tests/remote.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,57 @@ describe("Remote", function() {
243243
});
244244
});
245245

246+
it("can negotiate push", function() {
247+
var repo = this.repository;
248+
var wasCalled = false;
249+
250+
return Remote.create(repo, "bare", bareReposPath)
251+
.then(function(remote) {
252+
var fetchOpts = {
253+
callbacks: {
254+
pushNegotiation: function(update_list, len) {
255+
wasCalled = true;
256+
return NodeGit.Error.CODE.OK;
257+
}
258+
}
259+
};
260+
261+
var ref = "refs/heads/master";
262+
var refs = [ref + ":" + ref];
263+
264+
return remote.push(refs, fetchOpts)
265+
.then(function(res) {
266+
assert.ok(wasCalled);
267+
});
268+
});
269+
});
270+
271+
it("can reject push during negotiation", function() {
272+
var repo = this.repository;
273+
274+
return Remote.create(repo, "bare", bareReposPath)
275+
.then(function(remote) {
276+
var fetchOpts = {
277+
callbacks: {
278+
pushNegotiation: function(update_list, len) {
279+
return NodeGit.Error.CODE.ERROR;
280+
}
281+
}
282+
};
283+
284+
var ref = "refs/heads/master";
285+
var refs = [ref + ":" + ref];
286+
287+
return remote.push(refs, fetchOpts);
288+
})
289+
.then(function() {
290+
assert.fail("push should not succeed");
291+
})
292+
.catch(function(err) {
293+
assert.notEqual(err.code, "ERR_ASSERTION");
294+
});
295+
});
296+
246297
it("can get the default branch of a remote", function() {
247298
var remoteCallbacks = {
248299
certificateCheck: () => 0

0 commit comments

Comments
 (0)