use super::LanguagePredicate;
use crate::predicates::{
general::{is_git_repo, is_git_repo_clean},
Reportable,
};
use color_eyre::eyre::Result;
use std::path::Path;
pub struct GitDirtyRepoPredicate;
impl GitDirtyRepoPredicate {
fn is_git_repo(&self, path: &Path) -> bool {
is_git_repo(path)
}
fn is_git_repo_clean(&self, path: &Path) -> Result<bool> {
is_git_repo_clean(path)
}
}
impl Reportable for GitDirtyRepoPredicate {
fn report(&self, path: &std::path::Path) -> bool {
self.is_git_repo(path) && !(self.is_git_repo_clean(path).unwrap_or(true))
}
}
impl LanguagePredicate for GitDirtyRepoPredicate {
fn is_in_project(&self, path: &std::path::Path) -> bool {
let mut current_path = path.to_path_buf();
loop {
if current_path.join(".git").is_dir() {
return true;
}
if !current_path.pop() {
break;
}
}
false
}
}