use anyhow::{Result, bail};
use std::process::Command;
use super::git_output;
pub fn is_git_dirty() -> bool {
git_output(&["status", "--porcelain"])
.map(|s| !s.is_empty())
.unwrap_or(false)
}
pub fn local_git_user_name() -> Option<String> {
git_output(&["config", "user.name"])
.ok()
.filter(|s| !s.is_empty())
}
pub fn local_git_user_email() -> Option<String> {
git_output(&["config", "user.email"])
.ok()
.filter(|s| !s.is_empty())
}
pub fn check_git_available() -> Result<()> {
let output = Command::new("git").arg("--version").output();
match output {
Ok(o) if o.status.success() => Ok(()),
_ => bail!("git is not installed or not in PATH. Install git and try again."),
}
}
pub fn is_git_repo() -> bool {
git_output(&["rev-parse", "--git-dir"]).is_ok()
}
pub fn git_status_porcelain() -> String {
git_output(&["status", "--porcelain"]).unwrap_or_default()
}
pub fn is_shallow_clone() -> bool {
let git_dir = git_output(&["rev-parse", "--git-dir"]).unwrap_or_else(|_| ".git".to_string());
std::path::Path::new(&git_dir).join("shallow").exists()
}