Skip to main content

git_global/subcommands/
staged.rs

1//! The `staged` subcommand: shows `git status -s` for staged changes in all
2//! known repos with such changes.
3
4use crate::config::Config;
5use crate::errors::Result;
6use crate::parallel::{default_parallelism, run_parallel};
7use crate::repo::Repo;
8use crate::report::Report;
9
10/// Runs the `staged` subcommand.
11pub fn execute(mut config: Config) -> Result<Report> {
12    let include_untracked = config.show_untracked;
13    let repos = config.get_repos();
14    let mut report = Report::new(&repos);
15    report.pad_repo_output();
16
17    let results = run_parallel(repos, default_parallelism(), move |repo| {
18        let mut status_opts = git2::StatusOptions::new();
19        status_opts
20            .show(git2::StatusShow::Index)
21            .include_untracked(include_untracked)
22            .include_ignored(false);
23        repo.get_status_lines(status_opts)
24    });
25
26    for (path, lines) in results {
27        let repo = Repo::new(path);
28        for line in lines {
29            report.add_repo_message(&repo, line);
30        }
31    }
32
33    Ok(report)
34}