Skip to content

Commit 48ba2f1

Browse files
try restore relative path if wt_path was relative
1 parent 0d8cd1e commit 48ba2f1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

gix/src/open/repository.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,20 @@ impl ThreadSafeRepository {
301301
| gix_config::Source::EnvOverride => wt_path,
302302
_ => git_dir.join(wt_path).into(),
303303
};
304+
304305
// the reason we use realpath instead of gix_path::normalize here is because there
305306
// could be any intermediate symlinks (for example due to a symlinked .git
306307
// directory)
307-
worktree_dir = gix_path::realpath(wt_path).ok();
308+
worktree_dir = gix_path::realpath(&wt_path).ok();
309+
// restore the relative path if possible after resolving the absolute path
310+
if wt_path.is_relative() {
311+
if let Ok(cwd) = std::env::current_dir() {
312+
if let Some(rel_path) = worktree_dir.as_deref().and_then(|p| p.strip_prefix(&cwd).ok()) {
313+
worktree_dir = Some(rel_path.to_path_buf());
314+
}
315+
}
316+
}
317+
308318
#[allow(unused_variables)]
309319
if let Some(worktree_path) = worktree_dir.as_deref().filter(|wtd| !wtd.is_dir()) {
310320
gix_trace::warn!("The configured worktree path '{}' is not a directory or doesn't exist - `core.worktree` may be misleading", worktree_path.display());

0 commit comments

Comments
 (0)