fix(utils): handle empty commit messages in CommitInfo.format

Empty git commit messages made splitlines()[0] raise IndexError in format() and /dream-restore list rendering.
This commit is contained in:
santhreal authored and Xubin Ren committed 2026-07-18 17:22:16 +08:00
1 parent 6de5a0c5ca
commit 85097aa143
3 files changed
+15 -2

No files matched your search

+6 -1
View File
@@ -22,9 +22,14 @@ class CommitInfo:
message: str
timestamp: str # Formatted datetime
def subject(self) -> str:
"""First line of the commit message, or a placeholder if empty."""
lines = self.message.splitlines()
return lines[0] if lines else "(no message)"
def format(self, diff: str = "") -> str:
"""Format this commit for display, optionally with a diff."""
header = f"## {self.message.splitlines()[0]}\n`{self.sha}` — {self.timestamp}\n"
header = f"## {self.subject()}\n`{self.sha}` — {self.timestamp}\n"
if diff:
return f"{header}\n```diff\n{diff}\n```"
return f"{header}\n(no file changes)"