Skip to content

Commit

Permalink
Properly canonicalize the git root path
Browse files Browse the repository at this point in the history
Otherwise the later `strip_prefix` might fail, e.g. on Windows with UNC
paths.

Fixes #16
  • Loading branch information
badboy committed May 13, 2024
1 parent 24c3c8c commit 357a25b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 357a25b

Please sign in to comment.