@@ -48,7 +48,7 @@ fn dirwalk_api_and_icase_support() {
4848 last_pos += 1 ;
4949
5050 let entry = file
51- . entry_closest_to_directory ( dir)
51+ . entry_closest_to_directory_or_directory ( dir)
5252 . unwrap_or_else ( || panic ! ( "didn't find {dir}" ) ) ;
5353 assert ! (
5454 entry. path( & file) . starts_with( dir) ,
@@ -57,13 +57,75 @@ fn dirwalk_api_and_icase_support() {
5757
5858 let dir_upper: BString = dir. to_ascii_uppercase ( ) . into ( ) ;
5959 let other_entry = file
60- . entry_closest_to_directory_icase ( dir_upper. as_bstr ( ) , true , & icase)
60+ . entry_closest_to_directory_or_directory_icase ( dir_upper. as_bstr ( ) , true , & icase)
6161 . unwrap_or_else ( || panic ! ( "didn't find upper-cased {dir_upper}" ) ) ;
6262 assert_eq ! ( other_entry, entry, "the first entry is always the same, no matter what kind of search is conducted (as there are no clashes/ambiguities here)" ) ;
6363 }
6464 }
6565}
6666
67+ #[ test]
68+ fn entry_closest_to_directory_or_directory_with_submodule ( ) {
69+ let file = Fixture :: Generated ( "v2_all_file_kinds" ) . open ( ) ;
70+
71+ assert ! (
72+ file. entry_closest_to_directory_or_directory( "d" . into( ) ) . is_some( ) ,
73+ "this is a directory"
74+ ) ;
75+ assert ! (
76+ file. entry_closest_to_directory_or_directory( "sub" . into( ) ) . is_some( ) ,
77+ "this is a checked in repository, a directory itself"
78+ ) ;
79+ assert ! (
80+ file. entry_closest_to_directory_or_directory( "sub-worktree" . into( ) )
81+ . is_some( ) ,
82+ "a submodule that is officially registered, absolutely the same as 'sub' in the index."
83+ ) ;
84+ assert ! (
85+ file. entry_closest_to_directory_or_directory( "a" . into( ) ) . is_none( ) ,
86+ "'a' is a file, and we ask for a directory"
87+ ) ;
88+ }
89+
90+ #[ test]
91+ fn entry_closest_to_directory_or_directory_icase_with_submodule ( ) {
92+ let file = Fixture :: Generated ( "v2_all_file_kinds" ) . open ( ) ;
93+ let icase = file. prepare_icase_backing ( ) ;
94+
95+ assert ! (
96+ file. entry_closest_to_directory_or_directory_icase( "D" . into( ) , true , & icase)
97+ . is_some( ) ,
98+ "this is a directory"
99+ ) ;
100+ assert ! ( file
101+ . entry_closest_to_directory_or_directory_icase( "D" . into( ) , false , & icase)
102+ . is_none( ) ) ;
103+
104+ assert ! (
105+ file. entry_closest_to_directory_or_directory_icase( "SuB" . into( ) , true , & icase)
106+ . is_some( ) ,
107+ "this is a checked in repository, a directory itself"
108+ ) ;
109+ assert ! ( file
110+ . entry_closest_to_directory_or_directory_icase( "SuB" . into( ) , false , & icase)
111+ . is_none( ) ) ;
112+
113+ assert ! (
114+ file. entry_closest_to_directory_or_directory_icase( "SUB-worktree" . into( ) , true , & icase)
115+ . is_some( ) ,
116+ "a submodule that is officially registered, absolutely the same as 'sub' in the index."
117+ ) ;
118+ assert ! ( file
119+ . entry_closest_to_directory_or_directory_icase( "SUB-worktree" . into( ) , false , & icase)
120+ . is_none( ) ) ;
121+
122+ assert ! (
123+ file. entry_closest_to_directory_or_directory_icase( "A" . into( ) , true , & icase)
124+ . is_none( ) ,
125+ "'a' is a file, and we ask for a directory"
126+ ) ;
127+ }
128+
67129#[ test]
68130fn ignorecase_clashes_and_order ( ) {
69131 let file = icase_fixture ( ) ;
@@ -85,7 +147,7 @@ fn ignorecase_clashes_and_order() {
85147 last_pos += 1 ;
86148
87149 let entry = file
88- . entry_closest_to_directory ( dir)
150+ . entry_closest_to_directory_or_directory ( dir)
89151 . unwrap_or_else ( || panic ! ( "didn't find {dir}" ) ) ;
90152 assert ! (
91153 entry. path( & file) . starts_with( dir) ,
@@ -110,16 +172,16 @@ fn ignorecase_clashes_and_order() {
110172 ) ;
111173
112174 assert ! (
113- file. entry_closest_to_directory ( "d" . into( ) ) . is_none( ) ,
175+ file. entry_closest_to_directory_or_directory ( "d" . into( ) ) . is_none( ) ,
114176 "this is a file, and this directory search isn't case-sensitive"
115177 ) ;
116- let entry = file. entry_closest_to_directory ( "D" . into ( ) ) ;
178+ let entry = file. entry_closest_to_directory_or_directory ( "D" . into ( ) ) ;
117179 assert_eq ! (
118180 entry. map( |e| e. path( & file) ) . expect( "present" ) ,
119181 "D/B" ,
120182 "this is a directory, indeed, we find the first file in it"
121183 ) ;
122- let entry_icase = file. entry_closest_to_directory_icase ( "d" . into ( ) , true , & icase) ;
184+ let entry_icase = file. entry_closest_to_directory_or_directory_icase ( "d" . into ( ) , true , & icase) ;
123185 assert_eq ! (
124186 entry_icase, entry,
125187 "case-insensitive searches don't confuse directories and files, so `d` finds `D`, the directory."
@@ -325,6 +387,26 @@ fn check_prefix(index: &gix_index::State, prefix: &str, expected: &[&str]) {
325387 ) ;
326388}
327389
390+ #[ test]
391+ fn path_is_directory_with_submodule ( ) {
392+ let file = Fixture :: Generated ( "v2_all_file_kinds" ) . open ( ) ;
393+
394+ assert ! ( file. path_is_directory( "sub-worktree" . into( ) ) , "a submodule worktree" ) ;
395+ assert ! ( file. path_is_directory( "d" . into( ) ) , "a single-letter directory" ) ;
396+ assert ! (
397+ file. path_is_directory( "sub" . into( ) ) ,
398+ "this is the parent repository, and it was added as well"
399+ ) ;
400+ assert ! (
401+ !file. path_is_directory( "su" . into( ) ) ,
402+ "just a sub-string of the directory which doesn't match"
403+ ) ;
404+ assert ! (
405+ !file. path_is_directory( "a" . into( ) ) ,
406+ "a one-letter file isn't a directory"
407+ ) ;
408+ }
409+
328410#[ test]
329411fn path_is_directory ( ) {
330412 let file = Fixture :: Loose ( "ignore-case-realistic" ) . open ( ) ;
@@ -408,6 +490,43 @@ fn path_is_directory_icase() {
408490 ) ;
409491}
410492
493+ #[ test]
494+ fn path_is_directory_icase_with_submodule ( ) {
495+ let file = Fixture :: Generated ( "v2_all_file_kinds" ) . open ( ) ;
496+ let icase = file. prepare_icase_backing ( ) ;
497+
498+ assert ! (
499+ file. path_is_directory_icase( "SUB-worktree" . into( ) , true , & icase) ,
500+ "a submodule worktree"
501+ ) ;
502+ assert ! ( !file. path_is_directory_icase( "SUB-worktree" . into( ) , false , & icase) ) ;
503+
504+ assert ! (
505+ file. path_is_directory_icase( "D" . into( ) , true , & icase) ,
506+ "a single-letter directory"
507+ ) ;
508+ assert ! ( !file. path_is_directory_icase( "D" . into( ) , false , & icase) ) ;
509+
510+ assert ! (
511+ file. path_is_directory_icase( "SuB" . into( ) , true , & icase) ,
512+ "this is the parent repository, and it was added as well"
513+ ) ;
514+ assert ! ( !file. path_is_directory_icase( "SuB" . into( ) , false , & icase) ) ;
515+
516+ assert ! (
517+ !file. path_is_directory_icase( "Su" . into( ) , true , & icase) ,
518+ "just a sub-string of the directory which doesn't match"
519+ ) ;
520+ assert ! (
521+ !file. path_is_directory_icase( "A" . into( ) , true , & icase) ,
522+ "a one-letter file isn't a directory"
523+ ) ;
524+ assert ! (
525+ !file. path_is_directory_icase( "a" . into( ) , true , & icase) ,
526+ "a one-letter file isn't a directory, even with correct case"
527+ ) ;
528+ }
529+
411530#[ test]
412531fn path_is_directory_icase_with_clashes ( ) {
413532 let file = icase_fixture ( ) ;
0 commit comments