@@ -135,6 +135,47 @@ fn no_pathspecs_match_everything() -> crate::Result {
135
135
Ok ( ( ) )
136
136
}
137
137
138
+ #[ test]
139
+ fn included_directory_and_excluded_subdir_top_level_with_prefix ( ) -> crate :: Result {
140
+ let mut search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ ":/foo" , ":!/foo/target/" ] ) , None , Path :: new ( "foo" ) ) ?;
141
+ let m = search
142
+ . pattern_matching_relative_path ( "foo" . into ( ) , Some ( true ) , & mut no_attrs)
143
+ . expect ( "matches" ) ;
144
+ assert_eq ! ( m. kind, Verbatim ) ;
145
+
146
+ let m = search
147
+ . pattern_matching_relative_path ( "foo/bar" . into ( ) , Some ( false ) , & mut no_attrs)
148
+ . expect ( "matches" ) ;
149
+ assert_eq ! ( m. kind, Prefix ) ;
150
+
151
+ let m = search
152
+ . pattern_matching_relative_path ( "foo/target" . into ( ) , Some ( false ) , & mut no_attrs)
153
+ . expect ( "matches" ) ;
154
+ assert_eq ! ( m. kind, Prefix , "files named `target` are allowed" ) ;
155
+
156
+ let m = search
157
+ . pattern_matching_relative_path ( "foo/target" . into ( ) , Some ( true ) , & mut no_attrs)
158
+ . expect ( "matches" ) ;
159
+ assert ! ( m. is_excluded( ) , "directories named `target` are excluded" ) ;
160
+ assert_eq ! ( m. kind, Verbatim ) ;
161
+
162
+ let m = search
163
+ . pattern_matching_relative_path ( "foo/target/file" . into ( ) , Some ( false ) , & mut no_attrs)
164
+ . expect ( "matches" ) ;
165
+ assert ! ( m. is_excluded( ) , "everything below `target/` is also excluded" ) ;
166
+ assert_eq ! ( m. kind, Prefix ) ;
167
+
168
+ assert ! ( search. directory_matches_prefix( "foo/bar" . into( ) , false ) ) ;
169
+ assert ! ( search. directory_matches_prefix( "foo/bar" . into( ) , true ) ) ;
170
+ assert ! ( search. directory_matches_prefix( "foo" . into( ) , false ) ) ;
171
+ assert ! ( search. directory_matches_prefix( "foo" . into( ) , true ) ) ;
172
+ assert ! ( search. can_match_relative_path( "foo" . into( ) , Some ( true ) ) ) ;
173
+ assert ! ( search. can_match_relative_path( "foo" . into( ) , Some ( false ) ) ) ;
174
+ assert ! ( search. can_match_relative_path( "foo/hi" . into( ) , Some ( true ) ) ) ;
175
+ assert ! ( search. can_match_relative_path( "foo/hi" . into( ) , Some ( false ) ) ) ;
176
+ Ok ( ( ) )
177
+ }
178
+
138
179
#[ test]
139
180
fn starts_with ( ) -> crate :: Result {
140
181
let mut search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ "a/*" ] ) , None , Path :: new ( "" ) ) ?;
@@ -261,8 +302,14 @@ fn simplified_search_respects_all_excluded() -> crate::Result {
261
302
None ,
262
303
Path :: new ( "" ) ,
263
304
) ?;
264
- assert ! ( !search. can_match_relative_path( "b" . into( ) , None ) ) ;
265
- assert ! ( !search. can_match_relative_path( "a" . into( ) , None ) ) ;
305
+ assert ! (
306
+ search. can_match_relative_path( "b" . into( ) , None ) ,
307
+ "non-trivial excludes are ignored in favor of false-positives"
308
+ ) ;
309
+ assert ! (
310
+ search. can_match_relative_path( "a" . into( ) , None ) ,
311
+ "non-trivial excludes are ignored in favor of false-positives"
312
+ ) ;
266
313
assert ! ( search. can_match_relative_path( "c" . into( ) , None ) ) ;
267
314
assert ! ( search. can_match_relative_path( "c/" . into( ) , None ) ) ;
268
315
0 commit comments