git_global/subcommands/scan.rs
1//! The `scan` subcommand: scans the filesystem for git repos.
2//!
3//! By default, the user's home directory is walked, but this starting point can
4//! be configured in `~/.gitconfig`:
5//!
6//! ```bash
7//! $ git config --global global.basedir /some/path
8//! ```
9//!
10//! The `scan` subcommand caches the list of git repos paths it finds, and can
11//! be rerun at any time to refresh the list.
12
13use crate::config::Config;
14use crate::errors::Result;
15use crate::report::Report;
16
17/// Clears the cache, forces a rescan, and says how many repos were found.
18pub fn execute(mut config: Config) -> Result<Report> {
19 config.clear_cache();
20 let repos = config.get_repos();
21 let mut report = Report::new(&repos);
22 report.add_message(format!(
23 "Found {} repos. Use `git global list` to show them.",
24 repos.len()
25 ));
26 Ok(report)
27}