Skip to content
Open
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
24 changes: 24 additions & 0 deletions generate/input/callbacks.json
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,30 @@
"throttle": 100
}
},
"git_push_negotiation": {
"args": [
{
"name": "updates",
"type": "const git_push_update **"
},
{
"name": "len",
"type": "size_t"
},
{
"name": "payload",
"type": "void *"
}
],
"return": {
"type": "int",
"noResults": 0,
"success": 0,
"error": -1,
"cancel": -1,
"throttle": 100
}
},
"git_transport_cb": {
"args": [
{
Expand Down
19 changes: 18 additions & 1 deletion generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -3605,7 +3605,24 @@
"ignore": true
},
"push_negotiation": {
"ignore": true
"args": [
{
"name": "updates",
"cType": "const git_push_update **",
"cppClassName": "Array",
"jsClassName": "Array",
"arrayElementCppClassName": "GitPushUpdate",
"arrayLengthArgumentName": "len"
},
{
"name": "len",
"ctype": "size_t"
},
{
"name": "payload",
"ctype": "void *"
}
]
},
"sideband_progress": {
"ignore": false
Expand Down
5 changes: 5 additions & 0 deletions generate/input/libgit2-supplement.json
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,11 @@
"type": "git_push_update_reference_cb",
"name": "push_update_reference"
},
{
"type": "git_push_negotiation",
"name": "push_negotiation",
"isCallback": true
},
{
"type": "void *",
"name": "payload"
Expand Down
51 changes: 51 additions & 0 deletions test/tests/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,57 @@ describe("Remote", function() {
});
});

it("can negotiate push", function() {
var repo = this.repository;
var wasCalled = false;

return Remote.create(repo, "bare", bareReposPath)
.then(function(remote) {
var fetchOpts = {
callbacks: {
pushNegotiation: function(update_list, len) {
wasCalled = true;
return NodeGit.Error.CODE.OK;
}
}
};

var ref = "refs/heads/master";
var refs = [ref + ":" + ref];

return remote.push(refs, fetchOpts)
.then(function(res) {
assert.ok(wasCalled);
});
});
});

it("can reject push during negotiation", function() {
var repo = this.repository;

return Remote.create(repo, "bare", bareReposPath)
.then(function(remote) {
var fetchOpts = {
callbacks: {
pushNegotiation: function(update_list, len) {
return NodeGit.Error.CODE.ERROR;
}
}
};

var ref = "refs/heads/master";
var refs = [ref + ":" + ref];

return remote.push(refs, fetchOpts);
})
.then(function() {
assert.fail("push should not succeed");
})
.catch(function(err) {
assert.notEqual(err.code, "ERR_ASSERTION");
});
});

it("can get the default branch of a remote", function() {
var remoteCallbacks = {
certificateCheck: () => 0
Expand Down