diff --git a/src/dvcs.rs b/src/dvcs.rs index ad556fa..79cbee9 100644 --- a/src/dvcs.rs +++ b/src/dvcs.rs @@ -13,17 +13,18 @@ pub fn from_setting(setting: Option) -> Backend { pub enum Backend { Git, Mercurial, - Unknown(String) + Unknown(String), } impl Backend { - pub fn clone(&self, source: &str) -> bool { + pub fn clone(&self, source: &str, dest: &str) -> bool { match self { Backend::Git => { let status = Command::new("git") .arg("clone") .arg("--recursive") .arg(source) + .arg(dest) .status().expect("PROCESS ERROR!"); status.success() }, @@ -36,4 +37,22 @@ impl Backend { } } } + + /* + /// Runs an update on the repository in dest. Returns true + /// when an update was performed, false otherwise + pub fn update(&self, dest: &str) -> bool { + match self { + Backend::Git => { + + }, + Backend::Mercurial => { + + }, + Backend::Unknown(name) => { + eprintln!("Unknown DVCS: {}", name); + false + } + } + }*/ } diff --git a/src/main.rs b/src/main.rs index 403af78..cc9410e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,8 +33,9 @@ fn main() -> Result<(), std::io::Error> { log::debug("found_task", Some(&context)); // Maybe the task has a source we should clone? if let Some(source) = &task.source { + let source_dir = format!("{}/.{}", base_dir, task_name.as_str()); if task.cloned == false { - if !task.dvcs.clone(source) { + if !task.dvcs.clone(source, &source_dir) { context.insert("$i18n_source", &source); log::error("clone_failed", Some(&context)); // Skip further processing @@ -43,13 +44,17 @@ fn main() -> Result<(), std::io::Error> { // New repo just cloned // TODO: submodule and submodule updates println!("Downloaded source for {}", task_name); + std::env::set_current_dir(&source_dir); task.run(); } // So the cloned repo is already here maybe update? // Let's say there was an update and run println!("Task {} already exists, run it", task_name); + std::env::set_current_dir(&source_dir); task.run(); } else { + // No source, chaneg working dir to basedir + std::env::set_current_dir(&base_dir); println!("Taks {} doesn't have a source, run it", task_name); task.run_once(); }