Initial upload: TermDiagram v0.1.0
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-01-29 22:28:09 +00:00
parent 4cc8479499
commit afd408fd24

View File

@@ -0,0 +1,42 @@
from typing import List, Optional
from dataclasses import dataclass
from git import Repo
@dataclass
class CommitInfo:
hash: str
message: str
author: str
date: Optional[str] = None
class GitHistoryTracker:
def __init__(self, repo_path: str):
self.repo_path = repo_path
self.repo: Optional[Repo] = None
def is_git_repo(self) -> bool:
try:
self.repo = Repo(self.repo_path)
return not self.repo.bare
except:
return False
def get_commit_history(self, limit: int = 20) -> List[CommitInfo]:
if not self.repo:
if not self.is_git_repo():
return []
commits = []
for commit in self.repo.iter_commits("HEAD", max_count=limit):
commits.append(
CommitInfo(
hash=commit.hexsha[:7],
message=commit.message.strip(),
author=f"{commit.author.name} <{commit.author.email}>",
date=commit.committed_datetime.strftime("%Y-%m-%d %H:%M"),
)
)
return commits