Skip to content

Commit

Permalink
Blacklist the .git folder.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thedodd committed Mar 24, 2021
1 parent b74d95f commit 5201fd8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -80,13 +83,23 @@ impl WatchSystem {
Err(_) => return,
};

// Check ignored paths.
if ev_path
.ancestors()
.any(|path| self.ignored_paths.iter().any(|ignored_path| ignored_path == path))
{
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;
}
Expand Down

0 comments on commit 5201fd8

Please sign in to comment.