From afd408fd24f67ec2aae42df84423d8d8721463b3 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 29 Jan 2026 22:28:09 +0000 Subject: [PATCH] Initial upload: TermDiagram v0.1.0 --- src/termdiagram/git/history_tracker.py | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/termdiagram/git/history_tracker.py diff --git a/src/termdiagram/git/history_tracker.py b/src/termdiagram/git/history_tracker.py new file mode 100644 index 0000000..3b9fc40 --- /dev/null +++ b/src/termdiagram/git/history_tracker.py @@ -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