Skip to content

Instantly share code, notes, and snippets.

@CaptainYarb
Last active September 26, 2017 22:36
Show Gist options
  • Save CaptainYarb/dda3144c525be6c5d560cb4bcb3f8307 to your computer and use it in GitHub Desktop.
Save CaptainYarb/dda3144c525be6c5d560cb4bcb3f8307 to your computer and use it in GitHub Desktop.
Pull github repo in Node
var nodegit = require('nodegit');
var opts = {
fetchOpts: {
callbacks: {
credentials: function() {
return nodegit.Cred.sshKeyNew('git', './ssh/id_rsa.pub', './ssh/id_rsa', '');
},
certificateCheck: function() {
return 1;
}
}
}
};
nodegit.Clone('[email protected]:nodecraft/stackfiles.git', './stackfiles', opts).then(function(repo){
if(!(repo instanceof nodegit.Repository)){
throw new Error('Failed to pull');
}
return repo.getHeadCommit()
}).then(function(commit){
console.error('GREAT SUCCESS');
console.dir(commit.toString());
}).catch(function(err){
console.error('ERROR', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment