wsb 0.195.4199

Workspace - A tool suite for file operations, version management, and development workflow automation
Documentation
use crate::fleet::config::GitModules;
use crate::fleet::error::{Result, SuperGitError};
use crate::fleet::output::Formatter;
use crate::prelude::*;

pub fn execute(repo_root: &Path, output: Option<&Path>) -> Result<()> {
    let gitmodules = match GitModules::parse(repo_root) {
        Ok(gm) => gm,
        Err(SuperGitError::NoSubmodules) => GitModules {
            entries: Vec::new(),
            submodules: Vec::new(),
        },
        Err(e) => return Err(e),
    };

    let mut failed = 0usize;

    if gitmodules.submodules.is_empty() {
        crate::test_catalog::run(repo_root, output)
            .map_err(|e| SuperGitError::Other(e))?;
        return Ok(());
    }

    Formatter::print_info(&format!(
        "Generating test catalog for superproject + {} submodule(s)",
        gitmodules.submodules.len()
    ));

    Formatter::print_submodule_header("[SUPERPROJECT]");
    if let Err(e) = crate::test_catalog::run(repo_root, output) {
        Formatter::print_error(&format!("Superproject catalog failed: {}", e));
        failed += 1;
    }

    for submodule in &gitmodules.submodules {
        let sub_path = repo_root.join(&submodule.path);
        if !sub_path.exists() {
            Formatter::print_warning(&format!(
                "Submodule '{}' not initialized, skipping",
                submodule.name
            ));
            continue;
        }
        Formatter::print_submodule_header(&submodule.name);
        if let Err(e) = crate::test_catalog::run(&sub_path, None) {
            Formatter::print_error(&format!(
                "Catalog failed for '{}': {}",
                submodule.name, e
            ));
            failed += 1;
        }
    }

    if failed > 0 {
        return Err(SuperGitError::Other(format!(
            "{} repo(s) failed to generate test catalog",
            failed
        )));
    }

    Ok(())
}