roots: canonicalize the served path before deriving the host label
commit
d32ae27roots: canonicalize the served path before deriving the host label
discover(".") hands serve a relative path whose file_name is a dot, which folded to the repo fallback label.
Assisted-by: Claude:claude-fable-5
Reviews
No reviews of this commit yet — record a verdict below.
Start a review
crates/cli/git-ents/src/commands/serve.rs
@@ -87,6 +87,10 @@
/// the system resolver and needs an `/etc/hosts` line, which is why
/// the raw bound address is still printed alongside.
fn host_label(path: &std::path::Path) -> String {
+ // `LocalRoot::discover(".")` hands this a relative path whose
+ // file_name is `.`; canonicalize first so the label is the repo
+ // directory's real name, not the fallback.
+ let path = path.canonicalize().unwrap_or_else(|_io| path.to_path_buf());
let name = path
.file_name()
.map(|n| n.to_string_lossy().to_lowercase())
@@ -213,6 +217,14 @@
assert_eq!(host_label(std::path::Path::new(dir)), expected);
}
+ /// `discover(".")` hands serve a relative path; the label must be the
+ /// directory's real name, never the `repo` fallback `.`'s empty
+ /// file_name would fold to.
+ #[rstest]
+ fn host_label_canonicalizes_a_relative_path() {
+ assert_ne!(host_label(std::path::Path::new(".")), "repo");
+ }
+
#[rstest]
// @relation(roots.local, scope=function, role=Verifies)
fn serve_only_ever_binds_loopback() {