Skip to main content

submodule_kit/commands/is/
mod.rs

1use clap::ValueEnum;
2
3mod conditions;
4
5#[derive(ValueEnum, Clone)]
6pub enum IsCondition {
7    /// Check whether every submodule's parent-recorded commit matches the tip of its remote branch
8    AllUpToDate,
9    /// Check whether all submodules have been initialized and cloned locally
10    Populated,
11    /// Check whether all submodules have no uncommitted changes
12    Clean,
13    /// Check whether each submodule's locally checked-out commit matches what the parent records
14    Synced,
15    /// Check whether all submodules are checked out on their configured branch (not detached HEAD)
16    OnBranch,
17}
18
19pub fn run(conditions: Vec<IsCondition>) -> Result<bool, String> {
20    let mut all_ok = true;
21    for condition in conditions {
22        let passed = match condition {
23            IsCondition::AllUpToDate => conditions::all_up_to_date()?,
24            IsCondition::Populated => conditions::populated()?,
25            IsCondition::Clean => conditions::clean()?,
26            IsCondition::Synced => conditions::synced()?,
27            IsCondition::OnBranch => conditions::on_branch()?,
28        };
29        all_ok = all_ok && passed;
30    }
31    Ok(all_ok)
32}
33
34#[cfg(test)]
35pub(crate) static CWD_MUTEX: std::sync::Mutex<()> = std::sync::Mutex::new(());
36
37#[cfg(test)]
38#[path = "mod_tests.rs"]
39mod tests;