Skip to content

Commit

Permalink
Avoid empty user display paths
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
konstin committed Nov 21, 2024
1 parent 8149e63 commit 2f6345a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/uv-fs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ impl<T: AsRef<Path>> 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);
Expand All @@ -85,6 +90,11 @@ impl<T: AsRef<Path>> 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()
}

Expand Down

0 comments on commit 2f6345a

Please sign in to comment.