|
|
@ -1,80 +1,54 @@
|
|
|
|
use crate::{crash, info, workspace};
|
|
|
|
use crate::{crash, info, workspace};
|
|
|
|
use std::process::Command;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
|
|
|
|
pub fn reinit() {
|
|
|
|
pub fn init() {
|
|
|
|
let config = workspace::read_cfg();
|
|
|
|
let config = workspace::read_cfg();
|
|
|
|
let out = Command::new("bash")
|
|
|
|
if config.mode == "workspace" || config.mode == "repository" {
|
|
|
|
.args(&["-c", "ls -A"])
|
|
|
|
let dirs_raw = Command::new("ls").arg("-1").output().unwrap().stdout;
|
|
|
|
.output()
|
|
|
|
let dirs_string = String::from_utf8_lossy(&dirs_raw);
|
|
|
|
.unwrap()
|
|
|
|
let mut dirs = dirs_string.lines().collect::<Vec<&str>>();
|
|
|
|
.stdout;
|
|
|
|
|
|
|
|
let dirs_to_s = String::from_utf8_lossy(&*out);
|
|
|
|
|
|
|
|
let mut dirs = dirs_to_s.lines().collect::<Vec<&str>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let name = config.name.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dirs.retain(|x| *x != "mlc.toml");
|
|
|
|
dirs.retain(|x| *x != "mlc.toml");
|
|
|
|
dirs.retain(|x| *x != ".git");
|
|
|
|
dirs.sort_unstable();
|
|
|
|
if config.mode == "repository" {
|
|
|
|
|
|
|
|
dirs.retain(|x| *x != "out");
|
|
|
|
|
|
|
|
dirs.retain(|x| *x != name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info("Removing all repo directories to reinitialise".to_string());
|
|
|
|
let repos = &config.repo;
|
|
|
|
|
|
|
|
let mut repos = repos
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.map(|x| x.split('/').last().unwrap())
|
|
|
|
|
|
|
|
.collect::<Vec<&str>>();
|
|
|
|
|
|
|
|
|
|
|
|
Command::new("rm")
|
|
|
|
repos.sort_unstable();
|
|
|
|
.args(&["-rf", &dirs.join(" ")])
|
|
|
|
|
|
|
|
.spawn()
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.wait()
|
|
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if config.mode == "workspace" {
|
|
|
|
let mut diff = repos.clone();
|
|
|
|
for r in config.repo {
|
|
|
|
diff.retain(|x| !dirs.contains(x));
|
|
|
|
info(format!("Cloning (workspace mode): {}", r));
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
let mut diff_matches = vec![];
|
|
|
|
.args(&["clone", &r])
|
|
|
|
|
|
|
|
.spawn()
|
|
|
|
for &x in &diff {
|
|
|
|
.unwrap()
|
|
|
|
for y in config.repo.iter() {
|
|
|
|
.wait()
|
|
|
|
if x == y.split('/').last().unwrap() {
|
|
|
|
.unwrap();
|
|
|
|
diff_matches.push(y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if config.mode == "repository" {
|
|
|
|
|
|
|
|
for r in config.repo {
|
|
|
|
|
|
|
|
info(format!("Cloning (repository mode): {}", r));
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
|
|
|
|
.args(&["clone", &r])
|
|
|
|
|
|
|
|
.spawn()
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.wait()
|
|
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
crash("Invalid mode in mlc.toml".to_string(), 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn init() {
|
|
|
|
if diff.is_empty() {
|
|
|
|
let config = workspace::read_cfg();
|
|
|
|
info("All repos are already cloned".to_string());
|
|
|
|
if config.mode == "workspace" {
|
|
|
|
} else {
|
|
|
|
for r in config.repo {
|
|
|
|
info(format!("New/missing repos to clone: {}", diff.join(", ")));
|
|
|
|
info(format!("Cloning (workspace mode): {}", r));
|
|
|
|
for r in diff_matches {
|
|
|
|
|
|
|
|
info(format!(
|
|
|
|
|
|
|
|
"Cloning ({} mode): {}",
|
|
|
|
|
|
|
|
config.mode,
|
|
|
|
|
|
|
|
r.split('/').last().unwrap()
|
|
|
|
|
|
|
|
));
|
|
|
|
Command::new("git")
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["clone", &r])
|
|
|
|
.args(&["clone", r])
|
|
|
|
.spawn()
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if config.mode == "repository" {
|
|
|
|
|
|
|
|
for r in config.repo {
|
|
|
|
|
|
|
|
info(format!("Cloning (repository mode): {}", r));
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
|
|
|
|
.args(&["clone", &r])
|
|
|
|
|
|
|
|
.spawn()
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.wait()
|
|
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
crash("Invalid mode in mlc.toml".to_string(), 1);
|
|
|
|
crash("Invalid mode in mlc.toml".to_string(), 1);
|
|
|
|