summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan-Erik Rediger <janerik@fnordig.de>2024-05-13 14:07:20 +0200
committerJan-Erik Rediger <janerik@fnordig.de>2024-05-13 14:07:20 +0200
commit357a25b57df3a2e976c705d21c2767b42c115cce (patch)
treeabda0fe335c2ef15da2cb46b763efa9435a8cbfe /src
parent24c3c8cd2695a19e6ea777838cce6fe6326ad078 (diff)
Properly canonicalize the git root path
Otherwise the later `strip_prefix` might fail, e.g. on Windows with UNC paths. Fixes #16
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 1344958..add6dc0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -110,7 +110,7 @@ fn open_on(
Ok(path) => path,
Err(_) => return Ok(content.into()),
};
- let relpath = path.strip_prefix(git_root).unwrap();
+ let relpath = path.strip_prefix(git_root.canonicalize().unwrap()).unwrap();
log::trace!("Chapter path: {}", path.display());
log::trace!("Relative path: {}", relpath.display());
@@ -151,7 +151,9 @@ fn find_git(path: &Path) -> Option<PathBuf> {
git_dir = current_path.join(".git");
}
- git_dir.parent().map(|p| p.to_owned())
+ git_dir
+ .parent()
+ .and_then(|p| p.to_owned().canonicalize().ok())
}
#[cfg(test)]