use ignore::gitignore::Gitignore;
use std::path::Path;
use crate::constants;
use crate::constants::OXEN_HIDDEN_DIR;
use crate::model::LocalRepository;
pub fn create(repo: &LocalRepository) -> Option<Gitignore> {
let path = repo.path.join(constants::OXEN_IGNORE_FILE);
match Gitignore::new(path) {
(gitignore, None) => {
Some(gitignore)
}
(_, Some(err)) => {
log::debug!("Could not open .oxenignore file. Reason: {err}");
None
}
}
}
pub fn is_ignored(path: &Path, gitignore: &Option<Gitignore>, is_dir: bool) -> bool {
if path.starts_with(OXEN_HIDDEN_DIR) {
return true;
}
if let Some(gitignore) = gitignore
&& gitignore
.matched_path_or_any_parents(path, is_dir)
.is_ignore()
{
return true;
}
false
}