Skip to main content

get_head_commit

Function get_head_commit 

Source
pub fn get_head_commit(path: &Path) -> Option<String>
Expand description

Get the current commit hash (HEAD) of the git repository at path.

Opens path as a git repository (works with normal repos, worktrees, and submodules — anywhere a .git file or directory is reachable) and reads the HEAD commit object ID.

Returns None if:

  • The path is not a git repository
  • The repository has no commits (freshly init’d)
  • Any git operation fails

§Examples

use std::path::Path;
use seshat_scanner::get_head_commit;

if let Some(head) = get_head_commit(Path::new(".")) {
    println!("HEAD: {head}");
}