1
1
#![ allow( clippy:: result_large_err) ]
2
+ use gix_config:: file:: Metadata ;
3
+ use gix_features:: threading:: OwnShared ;
4
+ use gix_object:: bstr:: ByteSlice ;
5
+ use gix_path:: RelativePath ;
6
+ use std:: path:: Path ;
2
7
use std:: {
3
8
borrow:: Cow ,
4
9
collections:: { btree_map:: Entry , BTreeMap } ,
5
10
ffi:: OsStr ,
6
11
path:: PathBuf ,
7
12
} ;
8
13
9
- use gix_features:: threading:: OwnShared ;
10
- use gix_object:: bstr:: ByteSlice ;
11
- use gix_path:: RelativePath ;
12
-
13
14
use super :: { Error , Options } ;
14
15
use crate :: {
15
16
bstr:: BString ,
@@ -257,26 +258,32 @@ impl ThreadSafeRepository {
257
258
// core.worktree might be used to overwrite the worktree directory
258
259
if !config. is_bare {
259
260
let mut key_source = None ;
261
+ fn assure_config_is_from_current_repo (
262
+ section : & gix_config:: file:: Metadata ,
263
+ git_dir : & Path ,
264
+ current_dir : & Path ,
265
+ filter_config_section : & mut fn ( & Metadata ) -> bool ,
266
+ ) -> bool {
267
+ if !filter_config_section ( section) {
268
+ return false ;
269
+ }
270
+ // ignore worktree settings that aren't from our repository. This can happen
271
+ // with worktrees of submodules for instance.
272
+ section
273
+ . path
274
+ . as_deref ( )
275
+ . and_then ( |p| gix_path:: normalize ( p. into ( ) , current_dir) )
276
+ . is_some_and ( |config_path| config_path. starts_with ( git_dir) )
277
+ }
260
278
let worktree_path = config
261
279
. resolved
262
- . path_filter ( Core :: WORKTREE , {
263
- |section| {
264
- if !filter_config_section ( section) {
265
- return false ;
266
- }
267
- // ignore worktree settings that aren't from our repository. This can happen
268
- // with worktrees of submodules for instance.
269
- let is_config_in_our_repo = section
270
- . path
271
- . as_deref ( )
272
- . and_then ( |p| gix_path:: normalize ( p. into ( ) , current_dir) )
273
- . is_some_and ( |config_path| config_path. starts_with ( & git_dir) ) ;
274
- if !is_config_in_our_repo {
275
- return false ;
276
- }
280
+ . path_filter ( Core :: WORKTREE , |section| {
281
+ let res =
282
+ assure_config_is_from_current_repo ( section, & git_dir, current_dir, & mut filter_config_section) ;
283
+ if res {
277
284
key_source = Some ( section. source ) ;
278
- true
279
285
}
286
+ res
280
287
} )
281
288
. zip ( key_source) ;
282
289
if let Some ( ( wt, key_source) ) = worktree_path {
@@ -302,7 +309,9 @@ impl ThreadSafeRepository {
302
309
} else if !config. lenient_config
303
310
&& config
304
311
. resolved
305
- . boolean_filter ( Core :: WORKTREE , & mut filter_config_section)
312
+ . boolean_filter ( Core :: WORKTREE , |section| {
313
+ assure_config_is_from_current_repo ( section, & git_dir, current_dir, & mut filter_config_section)
314
+ } )
306
315
. is_some ( )
307
316
{
308
317
return Err ( Error :: from ( config:: Error :: ConfigTypedString (
0 commit comments