Skip to main content

git_global/subcommands/
ignore.rs

1//! The `ignore` subcommand: adds a pattern to the global.ignore gitconfig.
2
3use crate::config::Config;
4use crate::errors::{GitGlobalError, Result};
5use crate::report::Report;
6
7/// Adds the given pattern to global.ignore in gitconfig.
8pub fn execute(_config: Config, pattern: &str) -> Result<Report> {
9    let mut report = Report::new(&[]);
10    match Config::add_ignore_pattern(pattern) {
11        Ok(()) => {
12            report.add_message(format!(
13                "Added '{}' to global.ignore. Run `git global scan` to update the cache.",
14                pattern
15            ));
16        }
17        Err(e) => {
18            return Err(GitGlobalError::BadSubcommand(e));
19        }
20    }
21    Ok(report)
22}