FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Remote push by mattyclarkson · Pull Request #457 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) .json  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 5 additions & 0 deletions generate/input/descriptor.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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();
}
});
});
});

Back | FazBrowse Home | New Git URL