smartgit/ts/smartgit.clone.ts

37 lines
1.3 KiB
TypeScript

import "typings-global"
import plugins = require("./smartgit.plugins");
import SmartgitCheck = require("./smartgit.check");
export let clone = (options:{from:string,to:string}) => {
let done = plugins.Q.defer();
/***** URL Checks ******/
//TODO make smartstring URL test
/***** Path Checks ******/
if (!/^\/.*/.test(options.to)){ //check wether path is absolute
plugins.beautylog.error("It seems that the given path " + options.to + " is not absolute.");
return;
}
plugins.beautylog.log("Now cloning " + options.from);
var cloneOptions:any = {
fetchOpts: {
callbacks: {
certificateCheck: function() { return 1; },
credentials: function(url, userName) {
let gitRepo = new plugins.smartstring.GitRepo(url);
let sshDirPath:string;
let pubKey:string;
let privKey:string;
return plugins.nodegit.Cred.sshKeyMemoryNew(userName, pubKey, privKey, "");
}
}
}
};
var cloneRepository = plugins.nodegit.Clone.clone(options.from, options.to, cloneOptions)
.then(() => {
SmartgitCheck(cloneRepository);
done.resolve();
});
return done.promise;
};