anodizer_core/git/
status.rs1use anyhow::{Result, bail};
2use std::process::Command;
3
4use super::git_output;
5
6pub fn is_git_dirty() -> bool {
8 git_output(&["status", "--porcelain"])
9 .map(|s| !s.is_empty())
10 .unwrap_or(false)
11}
12
13pub fn local_git_user_name() -> Option<String> {
15 git_output(&["config", "user.name"])
16 .ok()
17 .filter(|s| !s.is_empty())
18}
19
20pub fn local_git_user_email() -> Option<String> {
22 git_output(&["config", "user.email"])
23 .ok()
24 .filter(|s| !s.is_empty())
25}
26
27pub fn check_git_available() -> Result<()> {
29 let output = Command::new("git").arg("--version").output();
30 match output {
31 Ok(o) if o.status.success() => Ok(()),
32 _ => bail!("git is not installed or not in PATH. Install git and try again."),
33 }
34}
35
36pub fn is_git_repo() -> bool {
38 git_output(&["rev-parse", "--git-dir"]).is_ok()
39}
40
41pub fn git_status_porcelain() -> String {
43 git_output(&["status", "--porcelain"]).unwrap_or_default()
44}
45
46pub fn is_shallow_clone() -> bool {
51 let git_dir = git_output(&["rev-parse", "--git-dir"]).unwrap_or_else(|_| ".git".to_string());
54 std::path::Path::new(&git_dir).join("shallow").exists()
55}