Mercurial > public > mercurial-scm > hg-stable
diff rust/rhg/src/commands/debugignorerhg.rs @ 52386:ff19ddb256b3
rust-ignore: add some tests of `debugignorerhg`, add flag -a to control output
The flag controls if the printed regex is intended to cover everything
(including the individually mentioned files), or just the regex that's
used in matching.
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Tue, 03 Dec 2024 14:39:00 +0000 |
parents | e2e49069eeb6 |
children | b89c934e6269 |
line wrap: on
line diff
--- a/rust/rhg/src/commands/debugignorerhg.rs Tue Dec 03 13:51:51 2024 +0000 +++ b/rust/rhg/src/commands/debugignorerhg.rs Tue Dec 03 14:39:00 2024 +0000 @@ -1,4 +1,5 @@ use crate::error::CommandError; +use clap::Arg; use hg::dirstate::status::StatusError; use hg::filepatterns::RegexCompleteness; use hg::matchers::get_ignore_matcher_pre; @@ -13,13 +14,22 @@ "; pub fn args() -> clap::Command { - clap::command!("debugignorerhg").about(HELP_TEXT) + clap::command!("debugignorerhg") + .arg( + Arg::new("all-patterns") + .help("include all patterns, including ones for exact file matches") + .short('a') + .action(clap::ArgAction::SetTrue) + .long("all-patterns"), + ).about(HELP_TEXT) } pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { let repo = invocation.repo?; + let args = invocation.subcommand_args; let ignore_file = repo.working_directory_vfs().join(".hgignore"); // TODO hardcoded + let all_patterns = args.get_flag("all-patterns"); let (ignore_matcher, warnings) = get_ignore_matcher_pre( vec![ignore_file], @@ -28,8 +38,13 @@ ) .map_err(StatusError::from)?; + let regex_config = if all_patterns { + RegexCompleteness::Complete + } else { + RegexCompleteness::ExcludeExactFiles + }; let ignore_matcher = ignore_matcher - .build_debug_matcher(RegexComprehensiveness::Comprehensive) + .build_debug_matcher(regex_config) .map_err(StatusError::from)?; if !warnings.is_empty() {