From 70b6e46e0d71c5fe323dcf94162e354d5d163cc5 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Mon, 2 Mar 2015 09:45:54 +0000 Subject: [PATCH 1/3] Normalize the remote push options --- lib/remote.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/remote.js b/lib/remote.js index 3b05b98d3..4b902d323 100644 --- a/lib/remote.js +++ b/lib/remote.js @@ -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 @@ -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; From 484104695df5bde5ebd08272cb7920141c9bc597 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Mon, 2 Mar 2015 10:36:18 +0000 Subject: [PATCH 2/3] Make git_remote_push options optional --- generate/input/descriptor.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index b1aaf8024..e6dcccfc5 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -1394,6 +1394,11 @@ "isAsync": true, "return": { "isErrorCode": true + }, + "args": { + "opts": { + "isOptional": true + } } }, "git_remote_set_callbacks": { From 2fb16f34a5edfff2a69cddd4672b5239505bbccd Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Mon, 2 Mar 2015 17:26:58 +0000 Subject: [PATCH 3/3] Remote push unit test --- test/tests/remote.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/tests/remote.js b/test/tests/remote.js index 104052a14..0d17a247f 100644 --- a/test/tests/remote.js +++ b/test/tests/remote.js @@ -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(); + } + }); + }); });