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.
--- 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() {
--- a/tests/test-hgignore.t Tue Dec 03 13:51:51 2024 +0000
+++ b/tests/test-hgignore.t Tue Dec 03 14:39:00 2024 +0000
@@ -16,6 +16,11 @@
$ hg debugignore
<nevermatcher>
+#if rhg
+ $ hg debugignorerhg
+
+#endif
+
Issue562: .hgignore requires newline at end:
$ touch foo
@@ -77,6 +82,11 @@
$ hg debugignore
<includematcher includes='(?i:.*\\.O$)|.*.hgignore'>
+#if rhg
+ $ hg debugignorerhg
+ (?i:.*\.O$)|.*.hgignore
+#endif
+
regex with flag is not the first one
$ echo 're:.hgignore' > .hgignore
@@ -88,6 +98,11 @@
$ hg debugignore
<includematcher includes='.*.hgignore|(?i:.*\\.O$)'>
+#if rhg
+ $ hg debugignorerhg
+ .*.hgignore|(?i:.*\.O$)
+#endif
+
flag in a pattern should affect that pattern only
$ echo 're:(?i)\.O$' > .hgignore
@@ -100,6 +115,11 @@
$ hg debugignore
<includematcher includes='(?i:.*\\.O$)|.*.HGIGNORE'>
+#if rhg
+ $ hg debugignorerhg
+ (?i:.*\.O$)|.*.HGIGNORE
+#endif
+
$ echo 're:.HGIGNORE' > .hgignore
$ echo 're:(?i)\.O$' >> .hgignore
$ hg status
@@ -110,6 +130,11 @@
$ hg debugignore
<includematcher includes='.*.HGIGNORE|(?i:.*\\.O$)'>
+#if rhg
+ $ hg debugignorerhg
+ .*.HGIGNORE|(?i:.*\.O$)
+#endif
+
Check that '^' after flag is properly detected.
$ echo 're:(?i)^[^a].*\.O$' > .hgignore
@@ -123,6 +148,11 @@
$ hg debugignore
<includematcher includes='(?i:^[^a].*\\.O$)|.*.HGIGNORE'>
+#if rhg
+ $ hg debugignorerhg
+ (?i:^[^a].*\.O$)|.*.HGIGNORE
+#endif
+
$ echo 're:.HGIGNORE' > .hgignore
$ echo 're:(?i)^[^a].*\.O$' >> .hgignore
$ hg status
@@ -134,6 +164,10 @@
$ hg debugignore
<includematcher includes='.*.HGIGNORE|(?i:^[^a].*\\.O$)'>
+#if rhg
+ $ hg debugignorerhg
+ .*.HGIGNORE|(?i:^[^a].*\.O$)
+#endif
further testing
---------------
@@ -317,6 +351,22 @@
? a.o
? dir/c.o
+ $ echo "rootglob:dir/b.o" > .hgignore
+ $ hg status
+ A dir/b.o
+ ? .hgignore
+ ? a.c
+ ? a.o
+ ? dir/c.o
+ ? syntax
+#if rhg
+ $ hg debugignorerhg -a
+ dir/b\.o(?:/|$)
+
+ $ hg debugignorerhg
+
+#endif
+
$ echo "relglob:*" > .hgignore
$ hg status
A dir/b.o
@@ -328,6 +378,11 @@
$ hg debugignore
<includematcher includes='.*(?:/|$)'>
+#if rhg
+ $ hg debugignorerhg
+ .*(?:/|$)
+#endif
+
$ hg debugignore b.o
b.o is ignored
(ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: '*') (glob)