git_workspace/commands/
switch_and_pull.rs

1use super::map_repositories;
2use crate::lockfile::Lockfile;
3use anyhow::Context;
4use std::path::Path;
5
6pub fn pull_all_repositories(workspace: &Path, threads: usize) -> anyhow::Result<()> {
7    let lockfile = Lockfile::new(workspace.join("workspace-lock.toml"));
8    let repositories = lockfile.read().with_context(|| "Error reading lockfile")?;
9
10    println!(
11        "Switching to the primary branch and pulling {} repositories",
12        repositories.len()
13    );
14
15    map_repositories(&repositories, threads, |r, progress_bar| {
16        r.switch_to_primary_branch(workspace)?;
17        let pull_args = match (&r.upstream, &r.branch) {
18            // This fucking sucks, but it's because my abstractions suck ass.
19            // I need to learn how to fix this.
20            (Some(_), Some(branch)) => vec![
21                "pull".to_string(),
22                "upstream".to_string(),
23                branch.to_string(),
24            ],
25            _ => vec!["pull".to_string()],
26        };
27        r.execute_cmd(workspace, progress_bar, "git", &pull_args)?;
28        Ok(())
29    })?;
30
31    Ok(())
32}