Skip to content

Commit d824b00

Browse files
committed
Expose git_push_negotiation Callback
1 parent 42faeed commit d824b00

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
@@ -927,6 +927,30 @@
927927
"throttle": 100
928928
}
929929
},
930+
"git_push_negotiation": {
931+
"args": [
932+
{
933+
"name": "updates",
934+
"type": "const git_push_update **"
935+
},
936+
{
937+
"name": "len",
938+
"type": "size_t"
939+
},
940+
{
941+
"name": "payload",
942+
"type": "void *"
943+
}
944+
],
945+
"return": {
946+
"type": "int",
947+
"noResults": 0,
948+
"success": 0,
949+
"error": -1,
950+
"cancel": -1,
951+
"throttle": 100
952+
}
953+
},
930954
"git_transport_cb": {
931955
"args": [
932956
{

generate/input/descriptor.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3540,7 +3540,24 @@
35403540
"ignore": true
35413541
},
35423542
"push_negotiation": {
3543-
"ignore": true
3543+
"args": [
3544+
{
3545+
"name": "updates",
3546+
"cType": "const git_push_update **",
3547+
"cppClassName": "Array",
3548+
"jsClassName": "Array",
3549+
"arrayElementCppClassName": "GitPushUpdate",
3550+
"arrayLengthArgumentName": "len"
3551+
},
3552+
{
3553+
"name": "len",
3554+
"ctype": "size_t"
3555+
},
3556+
{
3557+
"name": "payload",
3558+
"ctype": "void *"
3559+
}
3560+
]
35443561
},
35453562
"sideband_progress": {
35463563
"ignore": false

generate/input/libgit2-supplement.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,11 @@
15461546
"type": "git_push_update_reference_cb",
15471547
"name": "push_update_reference"
15481548
},
1549+
{
1550+
"type": "git_push_negotiation",
1551+
"name": "push_negotiation",
1552+
"isCallback": true
1553+
},
15491554
{
15501555
"type": "void *",
15511556
"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)