diff options
author | Jan-Erik Rediger <janerik@fnordig.de> | 2024-05-13 14:07:20 +0200 |
---|---|---|
committer | Jan-Erik Rediger <janerik@fnordig.de> | 2024-05-13 14:07:20 +0200 |
commit | 357a25b57df3a2e976c705d21c2767b42c115cce (patch) | |
tree | abda0fe335c2ef15da2cb46b763efa9435a8cbfe /src | |
parent | 24c3c8cd2695a19e6ea777838cce6fe6326ad078 (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.rs | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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)] |