@@ -12,8 +12,8 @@ mod create_directory {
12
12
}
13
13
14
14
#[ test]
15
- fn root_is_assumed_to_exist_and_files_in_root_do_not_create_directory ( ) {
16
- let dir = tempdir ( ) . unwrap ( ) ;
15
+ fn root_is_assumed_to_exist_and_files_in_root_do_not_create_directory ( ) -> crate :: Result {
16
+ let dir = tempdir ( ) ? ;
17
17
let mut cache = fs:: Cache :: new (
18
18
dir. path ( ) . join ( "non-existing-root" ) ,
19
19
fs:: cache:: State :: for_checkout ( false , Default :: default ( ) ) ,
@@ -23,9 +23,10 @@ mod create_directory {
23
23
) ;
24
24
assert_eq ! ( cache. num_mkdir_calls( ) , 0 ) ;
25
25
26
- let path = cache. at_path ( "hello" , Some ( false ) , panic_on_find) . unwrap ( ) . path ( ) ;
26
+ let path = cache. at_path ( "hello" , Some ( false ) , panic_on_find) ? . path ( ) ;
27
27
assert ! ( !path. parent( ) . unwrap( ) . exists( ) , "prefix itself is never created" ) ;
28
28
assert_eq ! ( cache. num_mkdir_calls( ) , 0 ) ;
29
+ Ok ( ( ) )
29
30
}
30
31
31
32
#[ test]
@@ -50,23 +51,24 @@ mod create_directory {
50
51
}
51
52
52
53
#[ test]
53
- fn existing_directories_are_fine ( ) {
54
+ fn existing_directories_are_fine ( ) -> crate :: Result {
54
55
let ( mut cache, tmp) = new_cache ( ) ;
55
- std:: fs:: create_dir ( tmp. path ( ) . join ( "dir" ) ) . unwrap ( ) ;
56
+ std:: fs:: create_dir ( tmp. path ( ) . join ( "dir" ) ) ? ;
56
57
57
- let path = cache. at_path ( "dir/file" , Some ( false ) , panic_on_find) . unwrap ( ) . path ( ) ;
58
+ let path = cache. at_path ( "dir/file" , Some ( false ) , panic_on_find) ? . path ( ) ;
58
59
assert ! ( path. parent( ) . unwrap( ) . is_dir( ) , "directory is still present" ) ;
59
60
assert ! ( !path. exists( ) , "it won't create the file" ) ;
60
61
assert_eq ! ( cache. num_mkdir_calls( ) , 1 ) ;
62
+ Ok ( ( ) )
61
63
}
62
64
63
65
#[ test]
64
- fn symlinks_or_files_in_path_are_forbidden_or_unlinked_when_forced ( ) {
66
+ fn symlinks_or_files_in_path_are_forbidden_or_unlinked_when_forced ( ) -> crate :: Result {
65
67
let ( mut cache, tmp) = new_cache ( ) ;
66
68
let forbidden = tmp. path ( ) . join ( "forbidden" ) ;
67
- std:: fs:: create_dir ( & forbidden) . unwrap ( ) ;
68
- symlink:: symlink_dir ( & forbidden, tmp. path ( ) . join ( "link-to-dir" ) ) . unwrap ( ) ;
69
- std:: fs:: write ( tmp. path ( ) . join ( "file-in-dir" ) , & [ ] ) . unwrap ( ) ;
69
+ std:: fs:: create_dir ( & forbidden) ? ;
70
+ symlink:: symlink_dir ( & forbidden, tmp. path ( ) . join ( "link-to-dir" ) ) ? ;
71
+ std:: fs:: write ( tmp. path ( ) . join ( "file-in-dir" ) , & [ ] ) ? ;
70
72
71
73
for dirname in & [ "file-in-dir" , "link-to-dir" ] {
72
74
cache. unlink_on_collision ( false ) ;
@@ -88,10 +90,7 @@ mod create_directory {
88
90
for dirname in & [ "link-to-dir" , "file-in-dir" ] {
89
91
cache. unlink_on_collision ( true ) ;
90
92
let relative_path = format ! ( "{}/file" , dirname) ;
91
- let path = cache
92
- . at_path ( & relative_path, Some ( false ) , panic_on_find)
93
- . unwrap ( )
94
- . path ( ) ;
93
+ let path = cache. at_path ( & relative_path, Some ( false ) , panic_on_find) ?. path ( ) ;
95
94
assert ! ( path. parent( ) . unwrap( ) . is_dir( ) , "directory was forcefully created" ) ;
96
95
assert ! ( !path. exists( ) ) ;
97
96
}
@@ -100,6 +99,7 @@ mod create_directory {
100
99
4 ,
101
100
"like before, but it unlinks what's there and tries again"
102
101
) ;
102
+ Ok ( ( ) )
103
103
}
104
104
105
105
fn new_cache ( ) -> ( fs:: Cache < ' static > , TempDir ) {
@@ -120,6 +120,7 @@ mod ignore_and_attributes {
120
120
use bstr:: { BStr , ByteSlice } ;
121
121
use std:: path:: Path ;
122
122
123
+ use git_glob:: pattern:: Case ;
123
124
use git_index:: entry:: Mode ;
124
125
use git_odb:: pack:: bundle:: write:: Options ;
125
126
use git_odb:: FindExt ;
@@ -153,23 +154,23 @@ mod ignore_and_attributes {
153
154
}
154
155
155
156
#[ test]
156
- fn check_against_baseline ( ) {
157
- let dir = git_testtools:: scripted_fixture_repo_read_only ( "make_ignore_and_attributes_setup.sh" ) . unwrap ( ) ;
157
+ fn check_against_baseline ( ) -> crate :: Result {
158
+ let dir = git_testtools:: scripted_fixture_repo_read_only ( "make_ignore_and_attributes_setup.sh" ) ? ;
158
159
let worktree_dir = dir. join ( "repo" ) ;
159
160
let git_dir = worktree_dir. join ( ".git" ) ;
160
161
let mut buf = Vec :: new ( ) ;
161
- let baseline = std:: fs:: read ( git_dir. parent ( ) . unwrap ( ) . join ( "git-check-ignore.baseline" ) ) . unwrap ( ) ;
162
+ let baseline = std:: fs:: read ( git_dir. parent ( ) . unwrap ( ) . join ( "git-check-ignore.baseline" ) ) ? ;
162
163
let user_exclude_path = dir. join ( "user.exclude" ) ;
163
164
assert ! ( user_exclude_path. is_file( ) ) ;
164
165
165
- let mut index = git_index:: File :: at ( git_dir. join ( "index" ) , Default :: default ( ) ) . unwrap ( ) ;
166
- let odb = git_odb:: at ( git_dir. join ( "objects" ) ) . unwrap ( ) ;
166
+ let mut index = git_index:: File :: at ( git_dir. join ( "index" ) , Default :: default ( ) ) ? ;
167
+ let odb = git_odb:: at ( git_dir. join ( "objects" ) ) ? ;
167
168
let case = git_glob:: pattern:: Case :: Sensitive ;
168
169
let state = git_worktree:: fs:: cache:: State :: for_add (
169
170
Default :: default ( ) , // TODO: attribute tests
170
171
git_worktree:: fs:: cache:: state:: Ignore :: new (
171
172
git_attributes:: MatchGroup :: from_overrides ( vec ! [ "!force-include" ] ) ,
172
- git_attributes:: MatchGroup :: from_git_dir ( & git_dir, Some ( user_exclude_path) , & mut buf) . unwrap ( ) ,
173
+ git_attributes:: MatchGroup :: from_git_dir ( & git_dir, Some ( user_exclude_path) , & mut buf) ? ,
173
174
None ,
174
175
case,
175
176
) ,
@@ -191,9 +192,7 @@ mod ignore_and_attributes {
191
192
let relative_path = git_path:: from_byte_slice ( relative_entry) ;
192
193
let is_dir = worktree_dir. join ( & relative_path) . metadata ( ) . ok ( ) . map ( |m| m. is_dir ( ) ) ;
193
194
194
- let platform = cache
195
- . at_entry ( relative_entry, is_dir, |oid, buf| odb. find_blob ( oid, buf) )
196
- . unwrap ( ) ;
195
+ let platform = cache. at_entry ( relative_entry, is_dir, |oid, buf| odb. find_blob ( oid, buf) ) ?;
197
196
198
197
let match_ = platform. matching_exclude_pattern ( ) ;
199
198
let is_excluded = platform. is_excluded ( ) ;
@@ -207,12 +206,7 @@ mod ignore_and_attributes {
207
206
if m. source . map_or ( false , |p| p. exists ( ) ) {
208
207
assert_eq ! (
209
208
m. source. map( |p| p. canonicalize( ) . unwrap( ) ) ,
210
- Some (
211
- worktree_dir
212
- . join( source_file. to_str_lossy( ) . as_ref( ) )
213
- . canonicalize( )
214
- . unwrap( )
215
- )
209
+ Some ( worktree_dir. join( source_file. to_str_lossy( ) . as_ref( ) ) . canonicalize( ) ?)
216
210
) ;
217
211
}
218
212
}
@@ -224,6 +218,11 @@ mod ignore_and_attributes {
224
218
}
225
219
}
226
220
}
227
- // TODO: at least one case-insensitive test
221
+
222
+ cache. set_case ( Case :: Fold ) ;
223
+ let platform = cache. at_entry ( "User-file-ANYWHERE" , Some ( false ) , |oid, buf| odb. find_blob ( oid, buf) ) ?;
224
+ let m = platform. matching_exclude_pattern ( ) . expect ( "match" ) ;
225
+ assert_eq ! ( m. pattern. text, "user-file-anywhere" ) ;
226
+ Ok ( ( ) )
228
227
}
229
228
}
0 commit comments