Hi I am trying to do a git push origin master
command with the help of Nodegit
, but it is resulting in an error,
var Git = require('nodegit');
function gitRemoteLookUp(repoPath) {
var open = Git.Repository.open;
var Remote = Git.Remote;
open(repoPath).then(function(repo){
return Remote.lookup(repo, "origin");
}).then(function(remote){
var ref = "refs/heads/master:remotes/origin/master";
var firstPass = true;
var options = {
callbacks: {
credentials: function(url, userName) {
if (firstPass) {
firstPass = false;
if (url.indexOf("https") === -1) {
return Git.Cred.sshKeyFromAgent('XYZ');
} else {
return Git.Cred.userpassPlaintextNew('XYZ', "XYZ");
}
} else {
return Git.Cred.defaultNew();
}
},
certificateCheck: function() {
return 1;
}
}
};
return remote.push(ref, options);
}).catch(function(err){
console.log(err);
})
}
I am using our internal ssh github server, which from the git Bash, for each push is asking for Username and Password.
Hence in hence in the code I have used the similar example as mentioned in the github site and also in the test site .
Pls help on this !!!!!!
I have found the answer to my own question,
The confusion lies in the SSH server and generic server,
i found two awesome post in the past nodegit questions,
var remote;
var repository;
function gitRemoteLookUp(repoPath) {
var open = Git.Repository.open;
open(repoPath).then(function(repo){
repository = repo;
return repo.getRemote('origin');
}).then(function(remoteResult){
remote = remoteResult;
remote.setCallbacks({
credentials: function(url, userName) {
// return Git.Cred.sshKeyFromAgent(userName);
return Git.Cred.userpassPlaintextNew('XYZ', "XYZ");
}
});
return remote.connect(Git.Enums.DIRECTION.PUSH);
}).then(function() {
console.log('remote Connected?', remote.connected())
return remote.push(
["refs/heads/master:refs/heads/master"],
null,
repository.defaultSignature(),
"Push to master")
}).then(function() {
console.log('remote Pushed!')
})
.catch(function(reason) {
console.log(reason);
});
}
The main issue lies in configuring the credentials in the Nodegit Library. Pls be careful in checking whether it is a SSH key based push or whether it works well with generic userpassPainTestNow mode. I have commented both the scenarios out there. These links turned out to be really useful for troubleshooting this. Nodegit: How to modify a file and push the changes? https://github.com/nodegit/nodegit/issues/463
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.