without autoescape
This commit is contained in:
33
cuddle_cli/src/util/git.rs
Normal file
33
cuddle_cli/src/util/git.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use std::env::current_dir;
|
||||
|
||||
use git2::Repository;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GitCommit {
|
||||
pub commit_sha: String,
|
||||
}
|
||||
|
||||
impl GitCommit {
|
||||
pub fn new() -> anyhow::Result<GitCommit> {
|
||||
let repo = Repository::open(current_dir().expect("having current_dir available")).map_err(
|
||||
|e| {
|
||||
log::debug!("{}", e);
|
||||
anyhow::anyhow!("could not open repository")
|
||||
},
|
||||
)?;
|
||||
let head_ref = repo
|
||||
.head()
|
||||
.map_err(|e| {
|
||||
log::warn!("{}", e);
|
||||
anyhow::anyhow!("could not get HEAD")
|
||||
})?
|
||||
.target()
|
||||
.ok_or(anyhow::anyhow!(
|
||||
"could not extract head -> target to commit_sha"
|
||||
))?;
|
||||
|
||||
Ok(Self {
|
||||
commit_sha: head_ref.to_string(),
|
||||
})
|
||||
}
|
||||
}
|
1
cuddle_cli/src/util/mod.rs
Normal file
1
cuddle_cli/src/util/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod git;
|
Reference in New Issue
Block a user