reworked init function to pull missing repos on re-run

main
jan Michal 3 years ago
parent 0c7046425a
commit 0ca6e2911c
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

@ -77,8 +77,6 @@ fn main() {
.subcommand(SubCommand::with_name("init").about( .subcommand(SubCommand::with_name("init").about(
"Clones all git repositories from mlc.toml branching from current directory", "Clones all git repositories from mlc.toml branching from current directory",
)) ))
.subcommand(SubCommand::with_name("reinit"))
.about("Removes all subdirectories and reinitialises")
.subcommand( .subcommand(
SubCommand::with_name("pull") SubCommand::with_name("pull")
.alias("update") .alias("update")
@ -136,10 +134,6 @@ fn main() {
operations::init(); operations::init();
} }
if let true = matches.is_present("reinit") {
operations::reinit();
}
if let true = matches.is_present("build") { if let true = matches.is_present("build") {
operations::build(&matches); operations::build(&matches);
} }

@ -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.sort_unstable();
dirs.retain(|x| *x != "mlc.toml"); let repos = &config.repo;
dirs.retain(|x| *x != ".git"); let mut repos = repos
if config.mode == "repository" { .iter()
dirs.retain(|x| *x != "out"); .map(|x| x.split('/').last().unwrap())
dirs.retain(|x| *x != name); .collect::<Vec<&str>>();
}
info("Removing all repo directories to reinitialise".to_string()); repos.sort_unstable();
Command::new("rm") let mut diff = repos.clone();
.args(&["-rf", &dirs.join(" ")]) diff.retain(|x| !dirs.contains(x));
.spawn()
.unwrap()
.wait()
.unwrap();
if config.mode == "workspace" { let mut diff_matches = vec![];
for r in config.repo {
info(format!("Cloning (workspace mode): {}", r));
Command::new("git")
.args(&["clone", &r])
.spawn()
.unwrap()
.wait()
.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 {
crash("Invalid mode in mlc.toml".to_string(), 1);
}
}
pub fn init() { for &x in &diff {
let config = workspace::read_cfg(); for y in config.repo.iter() {
if config.mode == "workspace" { if x == y.split('/').last().unwrap() {
for r in config.repo { diff_matches.push(y);
info(format!("Cloning (workspace mode): {}", r)); }
Command::new("git") }
.args(&["clone", &r])
.spawn()
.unwrap()
.wait()
.unwrap();
} }
} else if config.mode == "repository" {
for r in config.repo { if diff.is_empty() {
info(format!("Cloning (repository mode): {}", r)); info("All repos are already cloned".to_string());
Command::new("git") } else {
.args(&["clone", &r]) info(format!("New/missing repos to clone: {}", diff.join(", ")));
.spawn() for r in diff_matches {
.unwrap() info(format!(
.wait() "Cloning ({} mode): {}",
.unwrap(); config.mode,
r.split('/').last().unwrap()
));
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);

@ -6,10 +6,6 @@ mod init;
mod prune; mod prune;
mod pull; mod pull;
pub fn reinit() {
init::reinit();
}
pub fn init() { pub fn init() {
init::init(); init::init();
} }

Loading…
Cancel
Save