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
5 changes: 5 additions & 0 deletions generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,11 @@
"isAsync": true,
"return": {
"isErrorCode": true
},
"args": {
"opts": {
"isOptional": true
}
}
},
"git_remote_set_callbacks": {
Expand Down
18 changes: 18 additions & 0 deletions lib/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var lookupWrapper = require("./util/lookupWrapper");

var Remote = NodeGit.Remote;
var setCallbacks = Remote.prototype.setCallbacks;
var push = Remote.push;

/**
* Retrieves the remote by name
Expand All @@ -21,4 +22,21 @@ Remote.prototype.setCallbacks = function(callbacks) {
return setCallbacks.call(this, callbacks);
};

/**
* Pushes to a remote
*
* @async
* @param {Array} refSpecs The ref specs that should be pushed
* @param {PushOptions} options Options for the checkout
* @param {Signature} signature The identity to use for the reflog of the
* updated references
* @param {String} message The message to use for the update reflog messages
* @return {Number} error code
*/
Remote.push = function(refSpecs, options, signature, message) {
options = normalizeOptions(options, NodeGit.PushOptions);

return push.call(this, refSpecs, options, signature, message);
};

module.exports = Remote;
39 changes: 39 additions & 0 deletions test/tests/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,43 @@ describe("Remote", function() {
});
});

it("cannot push to a repository", function() {
this.timeout(5000);
var repo = this.repository;
var branch = "should-not-exist";
return Remote.lookup(repo, "origin")
.then(function(remote) {
remote.setCallbacks({
credentials: function(url, userName) {
if (url.indexOf("https") === -1) {
return NodeGit.Cred.sshKeyFromAgent(userName);
} else {
return NodeGit.Cred.userpassPlaintextNew(userName, "");
}
},
certificateCheck: function() {
return 1;
}
});
return remote;
})
.then(function(remote) {
var ref = "refs/heads/" + branch;
var refs = [ref + ":" + ref];
var signature = repo.defaultSignature();
return remote.push(refs, null, signature,
"Pushed '" + branch + "' for test");
})
.then(function() {
return Promise.reject(
new Error("should not be able to push to the repository"));
}, function(err) {
if (err.message.indexOf(401) === -1) {
return Promise.reject(
new Error("failed to return unauthorized status code"));
} else {
return Promise.resolve();
}
});
});
});