@@ -9,107 +9,6 @@ pub fn bare(git_dir_candidate: &Path) -> bool {
9
9
!( git_dir_candidate. join ( "index" ) . exists ( ) || ( git_dir_candidate. file_name ( ) == Some ( OsStr :: new ( DOT_GIT_DIR ) ) ) )
10
10
}
11
11
12
- /// Parse `<git_dir_candidate>/config` quickly to evaluate the value of the `bare` line, or return `true` if the file doesn't exist
13
- /// similar to what`guess_repository_type` seems to be doing.
14
- /// Return `None` if the `bare` line can't be found or the value of `bare` can't be determined.
15
- fn bare_by_config ( git_dir_candidate : & Path ) -> std:: io:: Result < Option < bool > > {
16
- match std:: fs:: read ( git_dir_candidate. join ( "config" ) ) {
17
- Ok ( buf) => Ok ( config:: parse_bare ( & buf) ) ,
18
- Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => Ok ( Some ( true ) ) ,
19
- Err ( err) => Err ( err) ,
20
- }
21
- }
22
-
23
- // Copied and adapted from `gix-config-value::boolean`.
24
- mod config {
25
- use bstr:: { BStr , ByteSlice } ;
26
-
27
- /// Note that we intentionally turn repositories that have a worktree configuration into bare repos,
28
- /// as we don't actually parse the worktree from the config file and expect the caller to do the right
29
- /// think when seemingly seeing bare repository.
30
- /// The reason we do this is to not incorrectly pretend this is a worktree.
31
- pub ( crate ) fn parse_bare ( buf : & [ u8 ] ) -> Option < bool > {
32
- let mut is_bare = None ;
33
- let mut has_worktree_configuration = false ;
34
- for line in buf. lines ( ) {
35
- if is_bare. is_none ( ) {
36
- if let Some ( line) = line. trim ( ) . strip_prefix ( b"bare" ) {
37
- is_bare = match line. first ( ) {
38
- None => Some ( true ) ,
39
- Some ( c) if * c == b'=' => parse_bool ( line. get ( 1 ..) ?. trim_start ( ) . as_bstr ( ) ) ,
40
- Some ( c) if c. is_ascii_whitespace ( ) => match line. split_once_str ( b"=" ) {
41
- Some ( ( _left, right) ) => parse_bool ( right. trim_start ( ) . as_bstr ( ) ) ,
42
- None => Some ( true ) ,
43
- } ,
44
- Some ( _other_char_) => None ,
45
- } ;
46
- continue ;
47
- }
48
- }
49
- if line. trim ( ) . strip_prefix ( b"worktree" ) . is_some ( ) {
50
- has_worktree_configuration = true ;
51
- break ;
52
- }
53
- }
54
- is_bare. map ( |bare| bare || has_worktree_configuration)
55
- }
56
-
57
- fn parse_bool ( value : & BStr ) -> Option < bool > {
58
- Some ( if parse_true ( value) {
59
- true
60
- } else if parse_false ( value) {
61
- false
62
- } else {
63
- use std:: str:: FromStr ;
64
- if let Some ( integer) = value. to_str ( ) . ok ( ) . and_then ( |s| i64:: from_str ( s) . ok ( ) ) {
65
- integer != 0
66
- } else {
67
- return None ;
68
- }
69
- } )
70
- }
71
-
72
- fn parse_true ( value : & BStr ) -> bool {
73
- value. eq_ignore_ascii_case ( b"yes" ) || value. eq_ignore_ascii_case ( b"on" ) || value. eq_ignore_ascii_case ( b"true" )
74
- }
75
-
76
- fn parse_false ( value : & BStr ) -> bool {
77
- value. eq_ignore_ascii_case ( b"no" )
78
- || value. eq_ignore_ascii_case ( b"off" )
79
- || value. eq_ignore_ascii_case ( b"false" )
80
- || value. is_empty ( )
81
- }
82
-
83
- #[ cfg( test) ]
84
- mod tests {
85
- use super :: * ;
86
-
87
- #[ test]
88
- fn various ( ) {
89
- for ( input, expected) in [
90
- ( "bare=true" , Some ( true ) ) ,
91
- ( "bare=1" , Some ( true ) ) ,
92
- ( "bare =1" , Some ( true ) ) ,
93
- ( "bare= yes" , Some ( true ) ) ,
94
- ( "bare=false" , Some ( false ) ) ,
95
- ( "bare=0" , Some ( false ) ) ,
96
- ( "bare=blah" , None ) ,
97
- ( "bare=" , Some ( false ) ) ,
98
- ( "bare= \n " , Some ( false ) ) ,
99
- ( "bare = true \n " , Some ( true ) ) ,
100
- ( "\t bare = false \n " , Some ( false ) ) ,
101
- ( "\n \t bare=true" , Some ( true ) ) ,
102
- ( "\n \t bare=true\n \t foo" , Some ( true ) ) ,
103
- ( "\n \t bare " , Some ( true ) ) ,
104
- ( "\n \t bare" , Some ( true ) ) ,
105
- ( "not found\n really" , None ) ,
106
- ] {
107
- assert_eq ! ( parse_bare( input. as_bytes( ) ) , expected, "{input:?}" ) ;
108
- }
109
- }
110
- }
111
- }
112
-
113
12
/// Returns true if `git_dir` is located within a `.git/modules` directory, indicating it's a submodule clone.
114
13
pub fn submodule_git_dir ( git_dir : & Path ) -> bool {
115
14
let mut last_comp = None ;
@@ -141,12 +40,15 @@ pub fn git(git_dir: &Path) -> Result<crate::repository::Kind, crate::is_git::Err
141
40
source : err,
142
41
path : git_dir. into ( ) ,
143
42
} ) ?;
144
- git_with_metadata ( git_dir, git_dir_metadata)
43
+ // precompose-unicode can't be known here, so we just default it to false, hoping it won't matter.
44
+ let cwd = gix_fs:: current_dir ( false ) ?;
45
+ git_with_metadata ( git_dir, git_dir_metadata, & cwd)
145
46
}
146
47
147
48
pub ( crate ) fn git_with_metadata (
148
49
git_dir : & Path ,
149
50
git_dir_metadata : std:: fs:: Metadata ,
51
+ cwd : & Path ,
150
52
) -> Result < crate :: repository:: Kind , crate :: is_git:: Error > {
151
53
#[ derive( Eq , PartialEq ) ]
152
54
enum Kind {
@@ -166,6 +68,8 @@ pub(crate) fn git_with_metadata(
166
68
{
167
69
// Fast-path: avoid doing the complete search if HEAD is already not there.
168
70
// TODO(reftable): use a ref-store to lookup HEAD if ref-tables should be supported, or detect ref-tables beforehand.
71
+ // Actually ref-tables still keep a specially marked `HEAD` around, so nothing might be needed here
72
+ // Even though our head-check later would fail without supporting it.
169
73
if !dot_git. join ( "HEAD" ) . exists ( ) {
170
74
return Err ( crate :: is_git:: Error :: MissingHead ) ;
171
75
}
@@ -236,25 +140,26 @@ pub(crate) fn git_with_metadata(
236
140
} ,
237
141
Kind :: MaybeRepo => {
238
142
let conformed_git_dir = if git_dir == Path :: new ( "." ) {
239
- gix_path:: realpath ( git_dir)
143
+ gix_path:: realpath_opts ( git_dir, cwd , gix_path :: realpath :: MAX_SYMLINKS )
240
144
. map ( Cow :: Owned )
241
145
. unwrap_or ( Cow :: Borrowed ( git_dir) )
242
146
} else {
243
- Cow :: Borrowed ( git_dir)
147
+ gix_path :: normalize ( git_dir . into ( ) , cwd ) . unwrap_or ( Cow :: Borrowed ( git_dir) )
244
148
} ;
245
149
if bare ( conformed_git_dir. as_ref ( ) ) || conformed_git_dir. extension ( ) == Some ( OsStr :: new ( "git" ) ) {
246
150
crate :: repository:: Kind :: PossiblyBare
247
151
} else if submodule_git_dir ( conformed_git_dir. as_ref ( ) ) {
248
152
crate :: repository:: Kind :: SubmoduleGitDir
249
- } else if conformed_git_dir. file_name ( ) == Some ( OsStr :: new ( DOT_GIT_DIR ) )
250
- || !bare_by_config ( conformed_git_dir. as_ref ( ) )
251
- . map_err ( |err| crate :: is_git:: Error :: Metadata {
252
- source : err,
253
- path : conformed_git_dir. join ( "config" ) ,
254
- } ) ?
255
- . ok_or ( crate :: is_git:: Error :: Inconclusive ) ?
256
- {
153
+ } else if conformed_git_dir. file_name ( ) == Some ( OsStr :: new ( DOT_GIT_DIR ) ) {
257
154
crate :: repository:: Kind :: WorkTree { linked_git_dir : None }
155
+ // } else if !bare_by_config(conformed_git_dir.as_ref())
156
+ // .map_err(|err| crate::is_git::Error::Metadata {
157
+ // source: err,
158
+ // path: conformed_git_dir.join("config"),
159
+ // })?
160
+ // .ok_or(crate::is_git::Error::Inconclusive)?
161
+ // {
162
+ // crate::repository::Kind::WorktreePossiblyInConfiguration
258
163
} else {
259
164
crate :: repository:: Kind :: PossiblyBare
260
165
}
0 commit comments