diff --git a/crates/uv-fs/src/path.rs b/crates/uv-fs/src/path.rs index 695bc5e42..3a3c051d8 100644 --- a/crates/uv-fs/src/path.rs +++ b/crates/uv-fs/src/path.rs @@ -65,6 +65,11 @@ impl> Simplified for T { fn user_display(&self) -> impl std::fmt::Display { let path = dunce::simplified(self.as_ref()); + // If current working directory is root, display the path as-is. + if CWD.ancestors().nth(1).is_none() { + return path.display(); + } + // Attempt to strip the current working directory, then the canonicalized current working // directory, in case they differ. let path = path.strip_prefix(CWD.simplified()).unwrap_or_else(|_| { @@ -78,6 +83,11 @@ impl> Simplified for T { fn user_display_from(&self, base: impl AsRef) -> impl std::fmt::Display { let path = dunce::simplified(self.as_ref()); + // If current working directory is root, display the path as-is. + if CWD.ancestors().nth(1).is_none() { + return path.display(); + } + // Attempt to strip the base, then the current working directory, then the canonicalized // current working directory, in case they differ. let path = path.strip_prefix(base.as_ref()).unwrap_or_else(|_| {