use color_eyre::eyre::Result;
use std::path::Path;
pub fn is_git_repo(path: &Path) -> bool {
path.join(".git").is_dir()
}
pub fn is_git_repo_clean(path: &Path) -> Result<bool> {
let output = std::process::Command::new("git")
.current_dir(path)
.args(&["status", "--porcelain"])
.output()
.expect("failed to execute process");
let output_str =
std::str::from_utf8(&output.stdout).expect("Failed to convert bytes to string");
let line_count = output_str
.split("\n")
.filter(|x| !x.trim().is_empty())
.count();
Ok(line_count == 0)
}
pub fn is_dir_empty(path: &Path) -> bool {
path.read_dir().map_or(true, |mut dir| dir.next().is_none())
}