use ignore::gitignore::{Gitignore, GitignoreBuilder};
use std::path::Path;
pub const INHERIT_IGNORE_FILE: &str = ".inherignore";
pub struct InheritIgnore {
inner: Gitignore,
}
impl InheritIgnore {
pub fn load(root: &Path) -> Self {
let file = root.join(INHERIT_IGNORE_FILE);
if !file.exists() {
return Self {
inner: Gitignore::empty(),
};
}
let mut builder = GitignoreBuilder::new(root);
let _ = builder.add(file);
let inner = builder.build().unwrap_or_else(|_| Gitignore::empty());
Self { inner }
}
pub fn is_ignored(&self, relative_path: &Path, is_dir: bool) -> bool {
let m = self.inner.matched(relative_path, is_dir);
m.is_ignore()
}
}
pub const ALWAYS_IGNORE: &[&str] = &["Inherit.toml", INHERIT_IGNORE_FILE, ".git"];