From 2f6345a9c2e4c460af721cd98bdae52c79faf674 Mon Sep 17 00:00:00 2001 From: konstin Date: Thu, 21 Nov 2024 12:23:17 +0100 Subject: [PATCH] Avoid empty user display paths Currently, user display returns an empty path if the current dir is the directory we are printing. This leads to odd messages such as > Including project.license-files at `` with `LICENSE*` or > Not a license files match: `` Instead, we display the current path as a dot. --- crates/uv-fs/src/path.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/uv-fs/src/path.rs b/crates/uv-fs/src/path.rs index 4e5e8049eb25..11626f5c4afb 100644 --- a/crates/uv-fs/src/path.rs +++ b/crates/uv-fs/src/path.rs @@ -64,6 +64,11 @@ impl> Simplified for T { return path.display(); } + if path.as_os_str() == "" { + // Avoid printing an empty string for the current directory + return Path::new(".").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(path); @@ -85,6 +90,11 @@ impl> Simplified for T { .strip_prefix(base.as_ref()) .unwrap_or_else(|_| path.strip_prefix(CWD.simplified()).unwrap_or(path)); + if path.as_os_str() == "" { + // Avoid printing an empty string for the current directory + return Path::new(".").display(); + } + path.display() }