File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ impl Search {
133133/// is ignored. 
134134/// Returns `false` if this pathspec has no chance of ever matching `relative_path`. 
135135pub  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 ( )   { 
137137            return  true ; 
138138        } 
139139        let  common_prefix_len = self . common_prefix_len . min ( relative_path. len ( ) ) ; 
@@ -194,7 +194,7 @@ impl Search {
194194/// When `leading` is `true`, then `d` matches `d/d` as well. Thus, `relative_path` must may be 
195195/// partially included in `pathspec`, otherwise it has to be fully included. 
196196pub  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 ( )   { 
198198            return  true ; 
199199        } 
200200        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 {
5757    Ok ( ( ) ) 
5858} 
5959
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+ 
6078#[ test]  
6179fn  directory_matches_prefix_leading ( )  -> crate :: Result  { 
6280    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