use crate::config::Config;
use crate::git;
use crate::ui;
pub fn run(config: Config, project: &str) {
ui::heading(&format!("Pulling all repos for {}", project));
let mut updated = 0usize;
let mut uptodate = 0usize;
let mut failed = 0usize;
let mut details: Vec<String> = Vec::new();
match git::pull(&config.main_repo.dir) {
Ok(git::PullResult::Updated(msg)) => {
ui::success(&format!("{} — updated", config.main_repo.name));
updated += 1;
if !msg.is_empty() {
details.push(format!("[{}] {}", config.main_repo.name, msg));
}
}
Ok(git::PullResult::UpToDate) => {
ui::info(&format!("{} — up-to-date", config.main_repo.name));
uptodate += 1;
}
Err(e) => {
ui::error(&format!("{} — {}", config.main_repo.name, e));
failed += 1;
}
}
if let Some(ref upstream) = config.main_repo.upstream {
if git::is_git_repo(&config.main_repo.dir) {
let _ = git::fetch_upstream(&config.main_repo.dir, upstream);
}
}
for repo in &config.repos {
match git::pull(&repo.abs_dir) {
Ok(git::PullResult::Updated(msg)) => {
ui::success(&format!("{} — updated", repo.name));
updated += 1;
if !msg.is_empty() && !msg.contains("Already up to date") {
details.push(format!("[{}] {}", repo.name, msg));
}
}
Ok(git::PullResult::UpToDate) => {
ui::info(&format!("{} — up-to-date", repo.name));
uptodate += 1;
}
Err(e) => {
ui::error(&format!("{} — {}", repo.name, e));
failed += 1;
}
}
}
for d in &details {
println!(" {}", d);
}
ui::separator();
println!(
" \x1b[32m{} updated\x1b[0m, {} up-to-date, \x1b[31m{} failed\x1b[0m",
updated, uptodate, failed
);
if failed > 0 {
std::process::exit(1);
}
}