smartgit/ts/smartgit.clone.ts

46 lines
1.7 KiB
TypeScript
Raw Normal View History

2016-06-12 14:46:59 +00:00
import "typings-global"
2016-03-30 23:59:45 +00:00
import plugins = require("./smartgit.plugins");
import SmartgitCheck = require("./smartgit.check");
2016-06-28 00:45:37 +00:00
export let clone = (optionsArg:{
from:string,
to:string,
keyPath?:string,
keyPassphrase?:string
}) => {
2016-03-30 23:59:45 +00:00
let done = plugins.Q.defer();
/***** URL Checks ******/
2016-06-12 14:46:59 +00:00
//TODO make smartstring URL test
2016-03-30 23:59:45 +00:00
/***** Path Checks ******/
2016-06-28 00:45:37 +00:00
if (!/^\/.*/.test(optionsArg.to)){ //check wether path is absolute
plugins.beautylog.error("It seems that the given path " + optionsArg.to + " is not absolute.");
2016-03-30 23:59:45 +00:00
return;
}
2016-06-28 00:45:37 +00:00
plugins.beautylog.log("Now cloning " + optionsArg.from);
2016-06-12 14:46:59 +00:00
var cloneOptions:any = {
fetchOpts: {
callbacks: {
certificateCheck: function() { return 1; },
credentials: function(url, userName) {
2016-06-27 23:21:40 +00:00
let gitRepo = new plugins.smartstring.GitRepo(url);
2016-06-28 00:45:37 +00:00
let host = gitRepo.host;
let sshDir = plugins.path.join(plugins.smartpath.get.home(),".ssh/")
let pubKeyPath = plugins.path.join(sshDir,host + ".pub");
let privKeyPath:string = plugins.path.join(sshDir,host);
if(!optionsArg.keyPassphrase) optionsArg.keyPassphrase = "";
return plugins.nodegit.Cred.sshKeyNew(userName, pubKeyPath, privKeyPath,optionsArg.keyPassphrase);
2016-06-12 14:46:59 +00:00
}
}
}
};
2016-06-28 00:45:37 +00:00
var cloneRepository = plugins.nodegit.Clone.clone(optionsArg.from, optionsArg.to, cloneOptions)
2016-06-12 14:46:59 +00:00
.then(() => {
SmartgitCheck(cloneRepository);
done.resolve();
2016-06-28 00:45:37 +00:00
},(err) => {
console.log(err);
2016-06-12 14:46:59 +00:00
});
2016-03-30 23:59:45 +00:00
return done.promise;
};