Avoid empty user display paths (#9312)

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.
This commit is contained in:
konsti
2024-11-21 20:56:50 +01:00
committed by GitHub
parent 82f96903ba
commit 55148c214e
+10
View File
@@ -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);
@@ -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()
}