@@ -3,13 +3,13 @@ mod checkout {
33 use std:: os:: unix:: prelude:: MetadataExt ;
44 use std:: {
55 fs,
6+ io:: ErrorKind ,
67 path:: { Path , PathBuf } ,
78 } ;
89
910 use git_object:: bstr:: ByteSlice ;
1011 use git_odb:: FindExt ;
11- use git_worktree:: fs:: Capabilities ;
12- use git_worktree:: index;
12+ use git_worktree:: { fs:: Capabilities , index, index:: checkout:: Collision } ;
1313 use tempfile:: TempDir ;
1414
1515 use crate :: fixture_path;
@@ -34,9 +34,11 @@ mod checkout {
3434 #[ test]
3535 fn symlinks_become_files_if_disabled ( ) -> crate :: Result {
3636 let opts = opts_with_symlink ( false ) ;
37- let ( source_tree, destination, _index) = checkout_index_in_tmp_dir ( opts, "make_mixed_without_submodules" ) ?;
37+ let ( source_tree, destination, _index, outcome) =
38+ checkout_index_in_tmp_dir ( opts, "make_mixed_without_submodules" ) ?;
3839
3940 assert_equality ( & source_tree, & destination, opts. fs . symlink ) ?;
41+ assert ! ( outcome. collisions. is_empty( ) ) ;
4042
4143 Ok ( ( ) )
4244 }
@@ -49,9 +51,11 @@ mod checkout {
4951 // skip if symlinks aren't supported anyway.
5052 return Ok ( ( ) ) ;
5153 } ;
52- let ( source_tree, destination, _index) = checkout_index_in_tmp_dir ( opts, "make_mixed_without_submodules" ) ?;
54+ let ( source_tree, destination, _index, outcome) =
55+ checkout_index_in_tmp_dir ( opts, "make_mixed_without_submodules" ) ?;
5356
5457 assert_equality ( & source_tree, & destination, opts. fs . symlink ) ?;
58+ assert ! ( outcome. collisions. is_empty( ) ) ;
5559 Ok ( ( ) )
5660 }
5761
@@ -62,11 +66,12 @@ mod checkout {
6266 return ;
6367 }
6468 let opts = opts_with_symlink ( true ) ;
65- let ( source_tree, destination, index) = checkout_index_in_tmp_dir ( opts , "make_ignorecase_collisions" ) . unwrap ( ) ;
66- assert_eq ! ( index . entries ( ) . len ( ) , 2 , "there is just one colliding item" ) ;
69+ let ( source_tree, destination, index, outcome ) =
70+ checkout_index_in_tmp_dir ( opts , "make_ignorecase_collisions" ) . unwrap ( ) ;
6771
6872 let num_files = assert_equality ( & source_tree, & destination, opts. fs . symlink ) . unwrap ( ) ;
6973 assert_eq ! ( num_files, index. entries( ) . len( ) , "it checks out all files" ) ;
74+ assert ! ( outcome. collisions. is_empty( ) ) ;
7075 }
7176
7277 #[ test]
@@ -76,21 +81,44 @@ mod checkout {
7681 return ;
7782 }
7883 let opts = opts_with_symlink ( true ) ;
79- let ( source_tree, destination, index) = checkout_index_in_tmp_dir ( opts, "make_ignorecase_collisions" ) . unwrap ( ) ;
80- assert_eq ! ( index. entries( ) . len( ) , 2 , "there is just one colliding item" ) ;
84+ let ( source_tree, destination, _index, outcome) =
85+ checkout_index_in_tmp_dir ( opts, "make_ignorecase_collisions" ) . unwrap ( ) ;
86+
87+ assert_eq ! (
88+ outcome. collisions,
89+ vec![
90+ Collision {
91+ path: "FILE_x" . into( ) ,
92+ error_kind: ErrorKind :: AlreadyExists ,
93+ } ,
94+ Collision {
95+ path: "d" . into( ) ,
96+ error_kind: ErrorKind :: AlreadyExists ,
97+ } ,
98+ Collision {
99+ path: "file_X" . into( ) ,
100+ error_kind: ErrorKind :: AlreadyExists ,
101+ } ,
102+ Collision {
103+ path: "file_x" . into( ) ,
104+ error_kind: ErrorKind :: AlreadyExists ,
105+ } ,
106+ ] ,
107+ "these files couldn't be checked out"
108+ ) ;
81109
82110 let source_files = dir_structure ( & source_tree) ;
83111 assert_eq ! (
84112 stripped_prefix( & source_tree, & source_files) ,
85- vec![ PathBuf :: from( "a " ) ] ,
86- "the source also only contains the first created file "
113+ vec![ PathBuf :: from( "d" ) , PathBuf :: from ( "file_x ") ] ,
114+ "plenty of collisions prevent a checkout "
87115 ) ;
88116
89117 let dest_files = dir_structure ( & destination) ;
90118 assert_eq ! (
91119 stripped_prefix( & destination, & dest_files) ,
92- vec![ PathBuf :: from( "A " ) ] ,
93- "it only creates the first file of a collision"
120+ vec![ PathBuf :: from( "D/B" ) , PathBuf :: from ( "D/C" ) , PathBuf :: from ( "FILE_X ") ] ,
121+ "we checkout files in order and generally handle collision detection differently, hence the difference "
94122 ) ;
95123 }
96124
@@ -138,20 +166,25 @@ mod checkout {
138166 fn checkout_index_in_tmp_dir (
139167 opts : index:: checkout:: Options ,
140168 name : & str ,
141- ) -> crate :: Result < ( PathBuf , TempDir , git_index:: File ) > {
169+ ) -> crate :: Result < (
170+ PathBuf ,
171+ TempDir ,
172+ git_index:: File ,
173+ git_worktree:: index:: checkout:: Outcome ,
174+ ) > {
142175 let source_tree = fixture_path ( name) ;
143176 let git_dir = source_tree. join ( ".git" ) ;
144177 let mut index = git_index:: File :: at ( git_dir. join ( "index" ) , Default :: default ( ) ) ?;
145178 let odb = git_odb:: at ( git_dir. join ( "objects" ) ) ?;
146179 let destination = tempfile:: tempdir ( ) ?;
147180
148- index:: checkout (
181+ let outcome = index:: checkout (
149182 & mut index,
150183 & destination,
151184 move |oid, buf| odb. find_blob ( oid, buf) . ok ( ) ,
152185 opts,
153186 ) ?;
154- Ok ( ( source_tree, destination, index) )
187+ Ok ( ( source_tree, destination, index, outcome ) )
155188 }
156189
157190 fn stripped_prefix ( prefix : impl AsRef < Path > , source_files : & [ PathBuf ] ) -> Vec < & Path > {
0 commit comments