Added /status command

This commit is contained in:
2025-04-28 13:06:55 +02:00
parent c96cb167b5
commit c4ebd1b891
6 changed files with 85 additions and 2 deletions

View File

@@ -0,0 +1,27 @@
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