Skip to main content

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//! Additional directories can be scanned by passing them as arguments:
11//!
12//! ```bash
13//! $ git global scan /extra/path1 /extra/path2
14//! ```
15//!
16//! The `scan` subcommand caches the list of git repos paths it finds, and can
17//! be rerun at any time to refresh the list.
18
19use std::path::PathBuf;
20
21use crate::config::Config;
22use crate::errors::Result;
23use crate::report::Report;
24
25/// Clears the cache, forces a rescan, and says how many repos were found.
26pub fn execute(
27    mut config: Config,
28    extra_paths: Vec<PathBuf>,
29) -> Result<Report> {
30    let repos = config.scan_with_extra_paths(&extra_paths);
31    let mut report = Report::new(&repos);
32    report.add_message(format!(
33        "Found {} repos. Use `git global list` to show them.",
34        repos.len()
35    ));
36    Ok(report)
37}