Clone to basedir/.task and set working dir there
This commit is contained in:
parent
e9bc8434a5
commit
f8f1f7fea5
23
src/dvcs.rs
23
src/dvcs.rs
|
@ -13,17 +13,18 @@ pub fn from_setting(setting: Option<String>) -> Backend {
|
||||||
pub enum Backend {
|
pub enum Backend {
|
||||||
Git,
|
Git,
|
||||||
Mercurial,
|
Mercurial,
|
||||||
Unknown(String)
|
Unknown(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Backend {
|
impl Backend {
|
||||||
pub fn clone(&self, source: &str) -> bool {
|
pub fn clone(&self, source: &str, dest: &str) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Backend::Git => {
|
Backend::Git => {
|
||||||
let status = Command::new("git")
|
let status = Command::new("git")
|
||||||
.arg("clone")
|
.arg("clone")
|
||||||
.arg("--recursive")
|
.arg("--recursive")
|
||||||
.arg(source)
|
.arg(source)
|
||||||
|
.arg(dest)
|
||||||
.status().expect("PROCESS ERROR!");
|
.status().expect("PROCESS ERROR!");
|
||||||
status.success()
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,9 @@ fn main() -> Result<(), std::io::Error> {
|
||||||
log::debug("found_task", Some(&context));
|
log::debug("found_task", Some(&context));
|
||||||
// Maybe the task has a source we should clone?
|
// Maybe the task has a source we should clone?
|
||||||
if let Some(source) = &task.source {
|
if let Some(source) = &task.source {
|
||||||
|
let source_dir = format!("{}/.{}", base_dir, task_name.as_str());
|
||||||
if task.cloned == false {
|
if task.cloned == false {
|
||||||
if !task.dvcs.clone(source) {
|
if !task.dvcs.clone(source, &source_dir) {
|
||||||
context.insert("$i18n_source", &source);
|
context.insert("$i18n_source", &source);
|
||||||
log::error("clone_failed", Some(&context));
|
log::error("clone_failed", Some(&context));
|
||||||
// Skip further processing
|
// Skip further processing
|
||||||
|
@ -43,13 +44,17 @@ fn main() -> Result<(), std::io::Error> {
|
||||||
// New repo just cloned
|
// New repo just cloned
|
||||||
// TODO: submodule and submodule updates
|
// TODO: submodule and submodule updates
|
||||||
println!("Downloaded source for {}", task_name);
|
println!("Downloaded source for {}", task_name);
|
||||||
|
std::env::set_current_dir(&source_dir);
|
||||||
task.run();
|
task.run();
|
||||||
}
|
}
|
||||||
// So the cloned repo is already here maybe update?
|
// So the cloned repo is already here maybe update?
|
||||||
// Let's say there was an update and run
|
// Let's say there was an update and run
|
||||||
println!("Task {} already exists, run it", task_name);
|
println!("Task {} already exists, run it", task_name);
|
||||||
|
std::env::set_current_dir(&source_dir);
|
||||||
task.run();
|
task.run();
|
||||||
} else {
|
} 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);
|
println!("Taks {} doesn't have a source, run it", task_name);
|
||||||
task.run_once();
|
task.run_once();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue