use crate::git::Git;
use miette::{Error, IntoDiagnostic, Result};
impl Git {
pub fn exists(self) -> bool {
self.repo.is_some()
}
pub fn get_branch(&self) -> Result<String> {
let repo = self.repo.as_ref().unwrap();
let head = repo.head().into_diagnostic()?;
let name = head.shorthand().unwrap().to_owned();
Ok(name)
}
pub fn get_tag(&self) -> Result<String> {
let repo = self.repo.as_ref().unwrap();
let head = repo.head().into_diagnostic()?;
if head.is_tag() {
let tag = head.name().unwrap().to_string();
Ok(tag)
} else {
Err(Error::msg("The current HEAD is not a tag"))
}
}
pub fn get_commit(&self) -> Result<String> {
let repo = self.repo.as_ref().unwrap();
let head = repo.head().into_diagnostic()?;
let commit_id = head.peel_to_commit().into_diagnostic()?.id().to_string();
Ok(commit_id)
}
}