From d6ef99e9efbc25b86c1c31bb8fcc8d1f03c1edef Mon Sep 17 00:00:00 2001 From: BanceDev Date: Sat, 28 Feb 2026 10:59:06 -0500 Subject: add short hash to list log --- src/util.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/util.rs') 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 { Ok(size) } +pub fn get_commit_hash(path: &Path) -> Result { + 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() { -- cgit v1.2.3-59-g8ed1b