Skip to content

Commit 852a882

Browse files
committed
Improve error handling of extra-watch-dirs watching, fix not watching whitelisted files outside book root
1 parent fb0cbc9 commit 852a882

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/cmd/watch.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ where
147147
let _ = watcher.watch(book.root.join("book.toml"), NonRecursive);
148148

149149
for dir in &book.config.build.extra_watch_dirs {
150-
let _ = watcher.watch(dir, Recursive);
150+
let path = dir.canonicalize().unwrap();
151+
if let Err(e) = watcher.watch(&path, Recursive) {
152+
error!("Error while watching extra directory {path:?}:\n {e:?}");
153+
std::process::exit(1);
154+
}
151155
}
152156

153157
info!("Listening for changes...");
@@ -170,7 +174,11 @@ where
170174
})
171175
.collect::<Vec<_>>();
172176

173-
let paths = remove_ignored_files(&book.root, &paths[..]);
177+
// If we are watching files outside the current repository (via extra-watch-dirs), then they are definitionally
178+
// ignored by gitignore. So we handle this case by including such files into the watched paths list.
179+
let any_external_paths = paths.iter().filter(|p| !p.starts_with(&book.root)).cloned();
180+
let mut paths = remove_ignored_files(&book.root, &paths[..]);
181+
paths.extend(any_external_paths);
174182

175183
if !paths.is_empty() {
176184
closure(paths, &book.root);

0 commit comments

Comments
 (0)