Looked around for an example, but couldn\'t find one. The documentation is not explained and I could not figure it out.
How to modify a file (README.md for example),
Rafael's solution works for sure although I might add that there is no needed to perform a .connect into the server. Here is a minimal approach on pushing a repo:
Pushing to master using only username and password authentication:
//Previous calls
}).then(function() {
return repo.getRemote("origin"); //Get origin remote
}).then(function(remote) {
return remote.push(["refs/heads/master:refs/heads/master"], {
callbacks: {
credentials: function(url, userName) {
console.log("Requesting creds");
return NodeGit.Cred.userpassPlaintextNew("[USERNAME]", "[PASSWORD]");
}
}
});
}).then(function(err) {
console.log("Push error number:");
console.log(err);
}).catch(function(err) {
console.log(err);
}).done(function(commitId) {
console.log("All done");
})
Pushing to myBranch over SSH auth:
//Previous calls
}).then(function() {
return repo.getRemote("origin"); //Get origin remote
}).then(function(remote) {
return remote.push(["refs/heads/myBranch:refs/heads/myBranch"], {
callbacks: {
credentials: function(url, userName) {
console.log("Requesting creds");
return NodeGit.Cred.sshKeyFromAgent(userName);
}
}
});
}).then(function(err) {
console.log("Push error number:");
console.log(err);
}).catch(function(err) {
console.log(err);
}).done(function(commitId) {
console.log("All done");
})