changeset 49408:90512ca6a255 stable

rust-matchers: fix behavior of `IncludeMatcher` with multiple includes This change adds a test for this fix as well as an additional test case that was useful in debugging this behavior.
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 29 Aug 2022 16:09:30 +0200
parents b10e4c19f8c5
children 6b4ad07b4d69
files rust/hg-core/src/matchers.rs
diffstat 1 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/matchers.rs	Tue Aug 30 10:52:32 2022 +0100
+++ b/rust/hg-core/src/matchers.rs	Mon Aug 29 16:09:30 2022 +0200
@@ -791,7 +791,7 @@
             dirs,
             parents,
         } = roots_dirs_and_parents(&ignore_patterns)?;
-        let prefix = ignore_patterns.iter().any(|k| match k.syntax {
+        let prefix = ignore_patterns.iter().all(|k| match k.syntax {
             PatternSyntax::Path | PatternSyntax::RelPath => true,
             _ => false,
         });
@@ -1094,6 +1094,31 @@
             matcher.visit_children_set(HgPath::new(b"dir/subdir/x")),
             VisitChildrenSet::This
         );
+
+        // Test multiple patterns
+        let matcher = IncludeMatcher::new(vec![
+            IgnorePattern::new(PatternSyntax::RelPath, b"foo", Path::new("")),
+            IgnorePattern::new(PatternSyntax::Glob, b"g*", Path::new("")),
+        ])
+        .unwrap();
+
+        assert_eq!(
+            matcher.visit_children_set(HgPath::new(b"")),
+            VisitChildrenSet::This
+        );
+
+        // Test multiple patterns
+        let matcher = IncludeMatcher::new(vec![IgnorePattern::new(
+            PatternSyntax::Glob,
+            b"**/*.exe",
+            Path::new(""),
+        )])
+        .unwrap();
+
+        assert_eq!(
+            matcher.visit_children_set(HgPath::new(b"")),
+            VisitChildrenSet::This
+        );
     }
 
     #[test]