From 852a882fab8961cb430845f2eaa06c7acb524db8 Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Mon, 7 Nov 2022 12:20:59 -0800 Subject: [PATCH] Improve error handling of extra-watch-dirs watching, fix not watching whitelisted files outside book root --- src/cmd/watch.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs index f5cf37f8..a3c9d546 100644 --- a/src/cmd/watch.rs +++ b/src/cmd/watch.rs @@ -147,7 +147,11 @@ where let _ = watcher.watch(book.root.join("book.toml"), NonRecursive); for dir in &book.config.build.extra_watch_dirs { - let _ = watcher.watch(dir, Recursive); + let path = dir.canonicalize().unwrap(); + if let Err(e) = watcher.watch(&path, Recursive) { + error!("Error while watching extra directory {path:?}:\n {e:?}"); + std::process::exit(1); + } } info!("Listening for changes..."); @@ -170,7 +174,11 @@ where }) .collect::>(); - let paths = remove_ignored_files(&book.root, &paths[..]); + // If we are watching files outside the current repository (via extra-watch-dirs), then they are definitionally + // ignored by gitignore. So we handle this case by including such files into the watched paths list. + let any_external_paths = paths.iter().filter(|p| !p.starts_with(&book.root)).cloned(); + let mut paths = remove_ignored_files(&book.root, &paths[..]); + paths.extend(any_external_paths); if !paths.is_empty() { closure(paths, &book.root);