| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1394,6 +1394,11 @@ | |||
| 1394 | 1394 | "isAsync": true, | |
| 1395 | 1395 | "return": { | |
| 1396 | 1396 | "isErrorCode": true | |
| 1397 | + }, | ||
| 1398 | + "args": { | ||
| 1399 | + "opts": { | ||
| 1400 | + "isOptional": true | ||
| 1401 | + } | ||
| 1397 | 1402 | } | |
| 1398 | 1403 | }, | |
| 1399 | 1404 | "git_remote_set_callbacks": { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ var lookupWrapper = require("./util/lookupWrapper"); | |||
| 4 | 4 | ||
| 5 | 5 | var Remote = NodeGit.Remote; | |
| 6 | 6 | var setCallbacks = Remote.prototype.setCallbacks; | |
| 7 | + var push = Remote.push; | ||
| 7 | 8 | ||
| 8 | 9 | /** | |
| 9 | 10 | * Retrieves the remote by name | |
@@ -21,4 +22,21 @@ Remote.prototype.setCallbacks = function(callbacks) { | |||
| 21 | 22 | return setCallbacks.call(this, callbacks); | |
| 22 | 23 | }; | |
| 23 | 24 | ||
| 25 | + /** | ||
| 26 | + * Pushes to a remote | ||
| 27 | + * | ||
| 28 | + * @async | ||
| 29 | + * @param {Array} refSpecs The ref specs that should be pushed | ||
| 30 | + * @param {PushOptions} options Options for the checkout | ||
| 31 | + * @param {Signature} signature The identity to use for the reflog of the | ||
| 32 | + * updated references | ||
| 33 | + * @param {String} message The message to use for the update reflog messages | ||
| 34 | + * @return {Number} error code | ||
| 35 | + */ | ||
| 36 | + Remote.push = function(refSpecs, options, signature, message) { | ||
| 37 | + options = normalizeOptions(options, NodeGit.PushOptions); | ||
| 38 | + | ||
| 39 | + return push.call(this, refSpecs, options, signature, message); | ||
| 40 | + }; | ||
| 41 | + | ||
| 24 | 42 | module.exports = Remote; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -171,4 +171,43 @@ describe("Remote", function() { | |||
| 171 | 171 | }); | |
| 172 | 172 | }); | |
| 173 | 173 | ||
| 174 | + it("cannot push to a repository", function() { | ||
| 175 | + this.timeout(5000); | ||
| 176 | + var repo = this.repository; | ||
| 177 | + var branch = "should-not-exist"; | ||
| 178 | + return Remote.lookup(repo, "origin") | ||
| 179 | + .then(function(remote) { | ||
| 180 | + remote.setCallbacks({ | ||
| 181 | + credentials: function(url, userName) { | ||
| 182 | + if (url.indexOf("https") === -1) { | ||
| 183 | + return NodeGit.Cred.sshKeyFromAgent(userName); | ||
| 184 | + } else { | ||
| 185 | + return NodeGit.Cred.userpassPlaintextNew(userName, ""); | ||
| 186 | + } | ||
| 187 | + }, | ||
| 188 | + certificateCheck: function() { | ||
| 189 | + return 1; | ||
| 190 | + } | ||
| 191 | + }); | ||
| 192 | + return remote; | ||
| 193 | + }) | ||
| 194 | + .then(function(remote) { | ||
| 195 | + var ref = "refs/heads/" + branch; | ||
| 196 | + var refs = [ref + ":" + ref]; | ||
| 197 | + var signature = repo.defaultSignature(); | ||
| 198 | + return remote.push(refs, null, signature, | ||
| 199 | + "Pushed '" + branch + "' for test"); | ||
| 200 | + }) | ||
| 201 | + .then(function() { | ||
| 202 | + return Promise.reject( | ||
| 203 | + new Error("should not be able to push to the repository")); | ||
| 204 | + }, function(err) { | ||
| 205 | + if (err.message.indexOf(401) === -1) { | ||
| 206 | + return Promise.reject( | ||
| 207 | + new Error("failed to return unauthorized status code")); | ||
| 208 | + } else { | ||
| 209 | + return Promise.resolve(); | ||
| 210 | + } | ||
| 211 | + }); | ||
| 212 | + }); | ||
| 174 | 213 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments