@@ -99,7 +99,7 @@ impl ThreadSafeRepository {
9999 }
100100
101101 /// Try to open a git repository in `fallback_directory` (can be worktree or `.git` directory) only if there is no override
102- /// from of the `gitdir` using git environment variables.
102+ /// of the `gitdir` using git environment variables.
103103 ///
104104 /// Use the `trust_map` to apply options depending in the trust level for `directory` or the directory it's overridden with.
105105 /// The `.git` directory whether given or computed is used for trust checks.
@@ -135,7 +135,7 @@ impl ThreadSafeRepository {
135135 }
136136 } ;
137137
138- // The be altered later based on `core.precomposeUnicode`.
138+ // To be altered later based on `core.precomposeUnicode`.
139139 let cwd = gix_fs:: current_dir ( false ) ?;
140140 let ( git_dir, worktree_dir) = gix_discover:: repository:: Path :: from_dot_git_dir ( path, path_kind, & cwd)
141141 . expect ( "we have sanitized path with is_git()" )
@@ -258,15 +258,35 @@ impl ThreadSafeRepository {
258258
259259 // core.worktree might be used to overwrite the worktree directory
260260 if !config. is_bare {
261- if let Some ( wt) = config. resolved . path_filter ( Core :: WORKTREE , & mut filter_config_section) {
261+ let mut key_source = None ;
262+ let worktree_path = config
263+ . resolved
264+ . path_filter ( Core :: WORKTREE , {
265+ |section| {
266+ let res = filter_config_section ( section) ;
267+ if res {
268+ key_source = Some ( section. source ) ;
269+ }
270+ res
271+ }
272+ } )
273+ . zip ( key_source) ;
274+ if let Some ( ( wt, key_source) ) = worktree_path {
262275 let wt_clone = wt. clone ( ) ;
263276 let wt_path = wt
264277 . interpolate ( interpolate_context ( git_install_dir. as_deref ( ) , home. as_deref ( ) ) )
265278 . map_err ( |err| config:: Error :: PathInterpolation {
266279 path : wt_clone. value . into_owned ( ) ,
267280 source : err,
268281 } ) ?;
269- worktree_dir = gix_path:: normalize ( git_dir. join ( wt_path) . into ( ) , current_dir) . map ( Cow :: into_owned) ;
282+ let wt_path = match key_source {
283+ gix_config:: Source :: Env
284+ | gix_config:: Source :: Cli
285+ | gix_config:: Source :: Api
286+ | gix_config:: Source :: EnvOverride => wt_path,
287+ _ => git_dir. join ( wt_path) . into ( ) ,
288+ } ;
289+ worktree_dir = gix_path:: normalize ( wt_path, current_dir) . map ( Cow :: into_owned) ;
270290 #[ allow( unused_variables) ]
271291 if let Some ( worktree_path) = worktree_dir. as_deref ( ) . filter ( |wtd| !wtd. is_dir ( ) ) {
272292 gix_trace:: warn!( "The configured worktree path '{}' is not a directory or doesn't exist - `core.worktree` may be misleading" , worktree_path. display( ) ) ;
@@ -284,7 +304,7 @@ impl ThreadSafeRepository {
284304 }
285305
286306 match worktree_dir {
287- None if !config. is_bare && refs. git_dir ( ) . extension ( ) == Some ( OsStr :: new ( gix_discover:: DOT_GIT_DIR ) ) => {
307+ None if !config. is_bare && refs. git_dir ( ) . file_name ( ) == Some ( OsStr :: new ( gix_discover:: DOT_GIT_DIR ) ) => {
288308 worktree_dir = Some ( git_dir. parent ( ) . expect ( "parent is always available" ) . to_owned ( ) ) ;
289309 }
290310 Some ( _) => {
0 commit comments