@@ -22,22 +22,37 @@ pub struct Context {
22
22
}
23
23
24
24
impl Context {
25
- /// try to determine all values in this context by probing them in the given `directory `, which
25
+ /// try to determine all values in this context by probing them in the given `git_dir `, which
26
26
/// should be on the file system the git repository is located on.
27
+ /// `git_dir` is a typical git repository, expected to be populated with the typical files like `config`.
27
28
///
28
29
/// All errors are ignored and interpreted on top of the default for the platform the binary is compiled for.
29
- pub fn probe ( directory : impl AsRef < std:: path:: Path > ) -> Self {
30
- let root = directory . as_ref ( ) ;
30
+ pub fn probe ( git_dir : impl AsRef < std:: path:: Path > ) -> Self {
31
+ let root = git_dir . as_ref ( ) ;
31
32
let ctx = Context :: default ( ) ;
32
33
Context {
33
34
symlink : Self :: probe_symlink ( root) . unwrap_or ( ctx. symlink ) ,
35
+ ignore_case : Self :: probe_ignore_case ( root) . unwrap_or ( ctx. ignore_case ) ,
34
36
..ctx
35
37
}
36
38
}
37
39
40
+ fn probe_ignore_case ( git_dir : & Path ) -> std:: io:: Result < bool > {
41
+ std:: fs:: metadata ( git_dir. join ( "cOnFiG" ) ) . map ( |_| true ) . or_else ( |err| {
42
+ if err. kind ( ) == std:: io:: ErrorKind :: NotFound {
43
+ Ok ( false )
44
+ } else {
45
+ Err ( err)
46
+ }
47
+ } )
48
+ }
49
+
38
50
fn probe_symlink ( root : & Path ) -> std:: io:: Result < bool > {
39
51
let src_path = root. join ( "__link_src_file" ) ;
40
- std:: fs:: File :: options ( ) . create_new ( true ) . write ( true ) . open ( & src_path) ?;
52
+ std:: fs:: OpenOptions :: new ( )
53
+ . create_new ( true )
54
+ . write ( true )
55
+ . open ( & src_path) ?;
41
56
let link_path = root. join ( "__file_link" ) ;
42
57
if symlink:: symlink_file ( & src_path, & link_path) . is_err ( ) {
43
58
std:: fs:: remove_file ( & src_path) ?;
0 commit comments