pets_tools 0.2.0

MusKitty multi-repo source management CLI — one command to clone, build, test, push, and publish 9 independent crate repositories
//! `pets pull <project>` — pull latest from all repos.

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();

    // Pull main repo
    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;
        }
    }

    // Also fetch upstream for main repo
    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);
        }
    }

    // Pull each crate repo
    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;
            }
        }
    }

    // Print details
    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);
    }
}