File tree 2 files changed +20
-2
lines changed 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ impl Search {
133
133
/// is ignored.
134
134
/// Returns `false` if this pathspec has no chance of ever matching `relative_path`.
135
135
pub fn can_match_relative_path ( & self , relative_path : & BStr , is_dir : Option < bool > ) -> bool {
136
- if self . patterns . is_empty ( ) {
136
+ if self . patterns . is_empty ( ) || relative_path . is_empty ( ) {
137
137
return true ;
138
138
}
139
139
let common_prefix_len = self . common_prefix_len . min ( relative_path. len ( ) ) ;
@@ -194,7 +194,7 @@ impl Search {
194
194
/// When `leading` is `true`, then `d` matches `d/d` as well. Thus, `relative_path` must may be
195
195
/// partially included in `pathspec`, otherwise it has to be fully included.
196
196
pub fn directory_matches_prefix ( & self , relative_path : & BStr , leading : bool ) -> bool {
197
- if self . patterns . is_empty ( ) {
197
+ if self . patterns . is_empty ( ) || relative_path . is_empty ( ) {
198
198
return true ;
199
199
}
200
200
let common_prefix_len = self . common_prefix_len . min ( relative_path. len ( ) ) ;
Original file line number Diff line number Diff line change @@ -57,6 +57,24 @@ fn directory_matches_prefix_starting_wildcards_always_match() -> crate::Result {
57
57
Ok ( ( ) )
58
58
}
59
59
60
+ #[ test]
61
+ fn empty_dir_always_matches ( ) -> crate :: Result {
62
+ for specs in [
63
+ & [ "*ir" ] as & [ _ ] ,
64
+ & [ ] ,
65
+ & [ "included" , ":!excluded" ] ,
66
+ & [ ":!all" , ":!excluded" ] ,
67
+ ] {
68
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( specs) , None , Path :: new ( "" ) ) ?;
69
+ assert ! ( search. directory_matches_prefix( "" . into( ) , false ) ) ;
70
+ assert ! ( search. directory_matches_prefix( "" . into( ) , false ) ) ;
71
+ for is_dir in [ Some ( true ) , Some ( false ) , None ] {
72
+ assert ! ( search. can_match_relative_path( "" . into( ) , is_dir) ) ;
73
+ }
74
+ }
75
+ Ok ( ( ) )
76
+ }
77
+
60
78
#[ test]
61
79
fn directory_matches_prefix_leading ( ) -> crate :: Result {
62
80
let search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ "d/d/generated/b" ] ) , None , Path :: new ( "" ) ) ?;
You can’t perform that action at this time.
0 commit comments