git_workspace/commands/
run.rs

1use super::map_repositories;
2use crate::lockfile::Lockfile;
3use crate::repository::Repository;
4use std::path::Path;
5
6/// Execute a command on all our repositories
7pub fn execute_cmd(
8    workspace: &Path,
9    threads: usize,
10    cmd: String,
11    args: Vec<String>,
12) -> anyhow::Result<()> {
13    // Read the lockfile
14    let lockfile = Lockfile::new(workspace.join("workspace-lock.toml"));
15    let repositories = lockfile.read()?;
16
17    // We only care about repositories that exist
18    let repos_to_fetch: Vec<Repository> = repositories
19        .iter()
20        .filter(|r| r.exists(workspace))
21        .cloned()
22        .collect();
23
24    println!(
25        "Running {} {} on {} repositories",
26        cmd,
27        args.join(" "),
28        repos_to_fetch.len()
29    );
30
31    // Run fetch on them
32    map_repositories(&repos_to_fetch, threads, |r, progress_bar| {
33        r.execute_cmd(workspace, progress_bar, &cmd, &args)
34    })?;
35    Ok(())
36}