@@ -3,13 +3,13 @@ mod checkout {
3
3
use std:: os:: unix:: prelude:: MetadataExt ;
4
4
use std:: {
5
5
fs,
6
+ io:: ErrorKind ,
6
7
path:: { Path , PathBuf } ,
7
8
} ;
8
9
9
10
use git_object:: bstr:: ByteSlice ;
10
11
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 } ;
13
13
use tempfile:: TempDir ;
14
14
15
15
use crate :: fixture_path;
@@ -34,9 +34,11 @@ mod checkout {
34
34
#[ test]
35
35
fn symlinks_become_files_if_disabled ( ) -> crate :: Result {
36
36
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" ) ?;
38
39
39
40
assert_equality ( & source_tree, & destination, opts. fs . symlink ) ?;
41
+ assert ! ( outcome. collisions. is_empty( ) ) ;
40
42
41
43
Ok ( ( ) )
42
44
}
@@ -49,9 +51,11 @@ mod checkout {
49
51
// skip if symlinks aren't supported anyway.
50
52
return Ok ( ( ) ) ;
51
53
} ;
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" ) ?;
53
56
54
57
assert_equality ( & source_tree, & destination, opts. fs . symlink ) ?;
58
+ assert ! ( outcome. collisions. is_empty( ) ) ;
55
59
Ok ( ( ) )
56
60
}
57
61
@@ -62,11 +66,12 @@ mod checkout {
62
66
return ;
63
67
}
64
68
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 ( ) ;
67
71
68
72
let num_files = assert_equality ( & source_tree, & destination, opts. fs . symlink ) . unwrap ( ) ;
69
73
assert_eq ! ( num_files, index. entries( ) . len( ) , "it checks out all files" ) ;
74
+ assert ! ( outcome. collisions. is_empty( ) ) ;
70
75
}
71
76
72
77
#[ test]
@@ -76,21 +81,44 @@ mod checkout {
76
81
return ;
77
82
}
78
83
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
+ ) ;
81
109
82
110
let source_files = dir_structure ( & source_tree) ;
83
111
assert_eq ! (
84
112
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 "
87
115
) ;
88
116
89
117
let dest_files = dir_structure ( & destination) ;
90
118
assert_eq ! (
91
119
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 "
94
122
) ;
95
123
}
96
124
@@ -138,20 +166,25 @@ mod checkout {
138
166
fn checkout_index_in_tmp_dir (
139
167
opts : index:: checkout:: Options ,
140
168
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
+ ) > {
142
175
let source_tree = fixture_path ( name) ;
143
176
let git_dir = source_tree. join ( ".git" ) ;
144
177
let mut index = git_index:: File :: at ( git_dir. join ( "index" ) , Default :: default ( ) ) ?;
145
178
let odb = git_odb:: at ( git_dir. join ( "objects" ) ) ?;
146
179
let destination = tempfile:: tempdir ( ) ?;
147
180
148
- index:: checkout (
181
+ let outcome = index:: checkout (
149
182
& mut index,
150
183
& destination,
151
184
move |oid, buf| odb. find_blob ( oid, buf) . ok ( ) ,
152
185
opts,
153
186
) ?;
154
- Ok ( ( source_tree, destination, index) )
187
+ Ok ( ( source_tree, destination, index, outcome ) )
155
188
}
156
189
157
190
fn stripped_prefix ( prefix : impl AsRef < Path > , source_files : & [ PathBuf ] ) -> Vec < & Path > {
0 commit comments