@@ -30,6 +30,7 @@ impl StageOne {
3030 gix_config:: Source :: Local ,
3131 git_dir_trust,
3232 lossy,
33+ lenient,
3334 ) ?;
3435
3536 // Note that we assume the repo is bare by default unless we are told otherwise. This is relevant if
@@ -64,6 +65,7 @@ impl StageOne {
6465 gix_config:: Source :: Worktree ,
6566 git_dir_trust,
6667 lossy,
68+ lenient,
6769 ) ?;
6870 config. append ( worktree_config) ;
6971 } ;
@@ -86,24 +88,47 @@ fn load_config(
8688 source : gix_config:: Source ,
8789 git_dir_trust : gix_sec:: Trust ,
8890 lossy : Option < bool > ,
91+ lenient : bool ,
8992) -> Result < gix_config:: File < ' static > , Error > {
90- buf. clear ( ) ;
9193 let metadata = gix_config:: file:: Metadata :: from ( source)
9294 . at ( & config_path)
9395 . with ( git_dir_trust) ;
9496 let mut file = match std:: fs:: File :: open ( & config_path) {
9597 Ok ( f) => f,
9698 Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => return Ok ( gix_config:: File :: new ( metadata) ) ,
97- Err ( err) => return Err ( err. into ( ) ) ,
99+ Err ( err) => {
100+ let err = Error :: Io {
101+ source : err,
102+ path : config_path,
103+ } ;
104+ if lenient {
105+ log:: warn!( "ignoring: {err:#?}" ) ;
106+ return Ok ( gix_config:: File :: new ( metadata) ) ;
107+ } else {
108+ return Err ( err) ;
109+ }
110+ }
111+ } ;
112+
113+ buf. clear ( ) ;
114+ if let Err ( err) = std:: io:: copy ( & mut file, buf) {
115+ let err = Error :: Io {
116+ source : err,
117+ path : config_path,
118+ } ;
119+ if lenient {
120+ log:: warn!( "ignoring: {err:#?}" ) ;
121+ } else {
122+ return Err ( err) ;
123+ }
98124 } ;
99- std:: io:: copy ( & mut file, buf) ?;
100125
101126 let config = gix_config:: File :: from_bytes_owned (
102127 buf,
103128 metadata,
104129 gix_config:: file:: init:: Options {
105130 includes : gix_config:: file:: includes:: Options :: no_follow ( ) ,
106- ..util:: base_options ( lossy)
131+ ..util:: base_options ( lossy, lenient )
107132 } ,
108133 ) ?;
109134
0 commit comments