from pathlib import Path import aiofiles # TODO Add documentation async def get_current_commit() -> str | None: head_path: Path = Path(".git/HEAD") if not head_path.exists(): return None async with aiofiles.open(head_path, "r", encoding="utf-8") as head_file: head_content: str = (await head_file.read()).strip() if not head_content.startswith("ref:"): return head_content head_ref_path: Path = Path(".git/").joinpath(" ".join(head_content.split(" ")[1:])) if not head_ref_path.exists(): return None async with aiofiles.open(head_ref_path, "r", encoding="utf-8") as head_ref_file: head_ref_content: str = (await head_ref_file.read()).strip() return head_ref_content