Skip to content

Commit

Permalink
improving git revision has function
Browse files Browse the repository at this point in the history
  • Loading branch information
sdat2 committed Sep 26, 2024
1 parent e888319 commit 216434b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sithom/misc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Miscillanious Utilities Module."""

from typing import Optional
import inspect
from sys import getsizeof
import subprocess
Expand Down Expand Up @@ -137,10 +138,18 @@ def get_byte_size(obj: object) -> str:
return human_readable_size(calculate_byte_size_recursively(obj))


def get_git_revision_hash() -> str:
def get_git_revision_hash(path: Optional[str] = None) -> str:
"""Get the git revision hash.
Args:
path (Optional[str], optional): The path to the git repository. Defaults to None.
If None then check use current path.
Returns:
str: The git revision hash.
"""
return subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip()
git_command = ["git", "rev-parse", "HEAD"]
if path:
# Add the --git-dir option if a path is provided
git_command = ["git", "--git-dir", f"{path}/.git", "rev-parse", "HEAD"]
return subprocess.check_output(git_command).decode("ascii").strip()

0 comments on commit 216434b

Please sign in to comment.