From c4f4f2a7a50c328a8e185dcecc06968302768624 Mon Sep 17 00:00:00 2001 From: ralphmodales Date: Tue, 30 Sep 2025 05:09:49 +0800 Subject: [PATCH] fix: make realpath conditional --- gix/src/open/repository.rs | 19 +++++++++++++++---- gix/tests/gix/status.rs | 21 --------------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/gix/src/open/repository.rs b/gix/src/open/repository.rs index bff4ab93098..dc76c531622 100644 --- a/gix/src/open/repository.rs +++ b/gix/src/open/repository.rs @@ -272,7 +272,13 @@ impl ThreadSafeRepository { section .path .as_deref() - .and_then(|p| gix_path::normalize(p.into(), current_dir)) + .and_then(|p| { + if p.exists() { + gix_path::realpath_opts(p, current_dir, gix_path::realpath::MAX_SYMLINKS).ok() + } else { + gix_path::normalize(p.into(), current_dir).map(Cow::into_owned) + } + }) .is_some_and(|config_path| config_path.starts_with(git_dir)) } let worktree_path = config @@ -305,9 +311,14 @@ impl ThreadSafeRepository { // the reason we use realpath instead of gix_path::normalize here is because there // could be any intermediate symlinks (for example due to a symlinked .git // directory) - worktree_dir = gix_path::realpath(&wt_path).ok(); - // restore the relative path if possible after resolving the absolute path - if wt_path.is_relative() { + let is_relative = wt_path.is_relative(); + worktree_dir = if wt_path.exists() { + gix_path::realpath(&wt_path).ok() + } else { + Some(wt_path.into_owned()) + }; + // restore the relative path if possible after resolving the absolute path + if is_relative { if let Some(rel_path) = worktree_dir.as_deref().and_then(|p| p.strip_prefix(current_dir).ok()) { worktree_dir = Some(rel_path.to_path_buf()); } diff --git a/gix/tests/gix/status.rs b/gix/tests/gix/status.rs index cb68289de4c..8b832f5c2c8 100644 --- a/gix/tests/gix/status.rs +++ b/gix/tests/gix/status.rs @@ -310,27 +310,6 @@ mod index_worktree { ); } - #[test] - fn submodule_in_symlinked_dir() -> crate::Result { - use crate::util::named_subrepo_opts; - let repo = named_subrepo_opts( - "make_submodule_with_symlinked_git_dir.sh", - "symlinked-git-dir", - gix::open::Options::isolated(), - )?; - let status = repo - .status(gix::progress::Discard)? - .index_worktree_options_mut(|opts| { - opts.sorting = - Some(gix::status::plumbing::index_as_worktree_with_renames::Sorting::ByPathCaseSensitive); - }) - .into_index_worktree_iter(None)?; - for change in status { - change?; - } - Ok(()) - } - #[test] fn submodule_modification() -> crate::Result { let repo = submodule_repo("modified-untracked-and-submodule-head-changed-and-modified")?;