use git2::{Repository, StatusOptions, Error};
pub struct RepoData {
pub is_empty_status: bool,
pub branch_name: String,
pub is_detached: bool,
}
pub fn is_git_working_directory_clean(path_to_project: &String) -> Result<RepoData, Error> {
let repo = match Repository::open(&path_to_project) {
Ok(repo) => repo,
Err(err) => return Err(err)
};
let head = match repo.head() {
Ok(head) => head,
Err(err) => return Err(err)
};
let mut status_opts = StatusOptions::new();
status_opts.include_untracked(true);
let statuses = repo.statuses(Some(&mut status_opts));
let statuses = match statuses {
Ok(statuses) => statuses,
Err(err) => return Err(err),
};
Ok(RepoData { is_empty_status: statuses.is_empty(), branch_name: if let Some(branch_name) = head.name() { branch_name.to_string() } else { "".to_string() } , is_detached: !head.is_branch() })
}