Skip to content

Commit fbb629c

Browse files
committed
normalize path in watch cmd
1 parent 94e0a44 commit fbb629c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/cmd/watch.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use ignore::gitignore::Gitignore;
44
use mdbook::errors::Result;
55
use mdbook::utils;
66
use mdbook::MDBook;
7+
use std::env;
78
use std::path::{Path, PathBuf};
89
use std::sync::mpsc::channel;
910
use std::thread::sleep;
@@ -87,11 +88,16 @@ fn find_gitignore(book_root: &Path) -> Option<PathBuf> {
8788
}
8889

8990
fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec<PathBuf> {
91+
let current_dir = env::current_dir().expect("Unable to determine the current directory");
92+
9093
paths
9194
.iter()
9295
.filter(|path| {
96+
let normalized_path = path
97+
.strip_prefix(&current_dir)
98+
.expect("Could not normalize path");
9399
!ignore
94-
.matched_path_or_any_parents(path, path.is_dir())
100+
.matched_path_or_any_parents(normalized_path, normalized_path.is_dir())
95101
.is_ignore()
96102
})
97103
.map(|path| path.to_path_buf())

0 commit comments

Comments
 (0)