aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/util.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/util.rs b/src/util.rs
index 8508377..7bd2142 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,4 +1,4 @@
-use git2::{Cred, FetchOptions, RemoteCallbacks, Repository, build::CheckoutBuilder};
+use git2::{Buf, Cred, FetchOptions, RemoteCallbacks, Repository, build::CheckoutBuilder};
use std::env;
use std::fs;
use std::io;
@@ -71,6 +71,14 @@ pub fn dir_size(path: &Path) -> std::io::Result<u64> {
Ok(size)
}
+pub fn get_commit_hash(path: &Path) -> Result<Buf, git2::Error> {
+ let repo = Repository::open(path)?;
+ let head = repo.head()?;
+
+ let commit = head.peel_to_commit()?;
+ Ok(repo.find_object(commit.id(), None)?.short_id()?)
+}
+
pub fn get_editor() -> String {
env::var("VISUAL")
.or_else(|_| env::var("EDITOR"))
@@ -147,11 +155,9 @@ pub fn yn_prompt(prompt: &str) -> bool {
print!("{} [y/n]: ", prompt);
io::stdout().flush().unwrap();
- // Read input from user
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
- // Normalize input
let input = input.trim().to_lowercase();
match input.as_str() {