diff options
| author | 2026-02-28 10:59:06 -0500 | |
|---|---|---|
| committer | 2026-02-28 10:59:06 -0500 | |
| commit | d6ef99e9efbc25b86c1c31bb8fcc8d1f03c1edef (patch) | |
| tree | a16e728c749f8a96c34233acb9c76ba815f0c8e1 /src/util.rs | |
| parent | add package collect helpers to reduce duplicity (diff) | |
add short hash to list log
Diffstat (limited to '')
| -rw-r--r-- | src/util.rs | 12 |
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() { |
