Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ log = "0.4.17"
memchr = "2.5.0"
opener = "0.6.1"
pulldown-cmark = { version = "0.9.3", default-features = false }
pathdiff = "0.2.1"
regex = "1.8.1"
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
Expand Down
8 changes: 7 additions & 1 deletion src/cmd/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use ignore::gitignore::Gitignore;
use mdbook::errors::Result;
use mdbook::utils;
use mdbook::MDBook;
use pathdiff::diff_paths;
use std::env;
use std::path::{Path, PathBuf};
use std::sync::mpsc::channel;
use std::thread::sleep;
Expand Down Expand Up @@ -87,11 +89,15 @@ fn find_gitignore(book_root: &Path) -> Option<PathBuf> {
}

fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec<PathBuf> {
let current_dir = env::current_dir().expect("Unable to determine the current directory");

paths
.iter()
.filter(|path| {
let relative_path =
diff_paths(&current_dir, &path).expect("One of the paths should be an absolute");
!ignore
.matched_path_or_any_parents(path, path.is_dir())
.matched_path_or_any_parents(&relative_path, relative_path.is_dir())
.is_ignore()
})
.map(|path| path.to_path_buf())
Expand Down