From 5201fd8128c8e2f4afaf7d22c0fc3b370cca0dd9 Mon Sep 17 00:00:00 2001 From: Anthony Dodd Date: Wed, 24 Mar 2021 08:24:51 -0500 Subject: [PATCH] Blacklist the .git folder. Definitely going to keep this issue simple. Lots more we could do here with automatically ignoring all of the contents of a repo's `.gitignore` and such, however folks can still ignore these in their config quite easily. closes #148 --- src/watch.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/watch.rs b/src/watch.rs index 932a406e..7d26e798 100644 --- a/src/watch.rs +++ b/src/watch.rs @@ -10,6 +10,9 @@ use notify::{watcher, DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher use crate::build::BuildSystem; use crate::config::RtcWatch; +/// Blacklisted path segments which are ignored by the watcher by default. +const BLACKLIST: [&str; 1] = [".git"]; + /// A watch system wrapping a build system and a watcher. pub struct WatchSystem { /// The build system. @@ -80,6 +83,7 @@ impl WatchSystem { Err(_) => return, }; + // Check ignored paths. if ev_path .ancestors() .any(|path| self.ignored_paths.iter().any(|ignored_path| ignored_path == path)) @@ -87,6 +91,15 @@ impl WatchSystem { return; // Don't emit a notification if path is ignored. } + // Check blacklisted paths. + if ev_path + .components() + .filter_map(|segment| segment.as_os_str().to_str()) + .any(|segment| BLACKLIST.contains(&segment)) + { + return; // Don't emit a notification as path is on the blacklist. + } + tracing::info!("change detected in {:?}", ev_path); let _ = self.build.build().await; }