smartgit/ts/smartgit.clone.ts

33 lines
1.1 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-12 14:46:59 +00:00
export let clone = (options:{from:string,to: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 ******/
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);
2016-06-12 14:46:59 +00:00
var cloneOptions:any = {
fetchOpts: {
callbacks: {
certificateCheck: function() { return 1; },
credentials: function(url, userName) {
return plugins.nodegit.Cred.sshKeyFromAgent(userName);
}
}
}
};
var cloneRepository = plugins.nodegit.Clone.clone(options.from, options.to, cloneOptions)
.then(() => {
SmartgitCheck(cloneRepository);
done.resolve();
});
2016-03-30 23:59:45 +00:00
return done.promise;
};