From 4e3496059525597970466ce7a6e699e17c239302 Mon Sep 17 00:00:00 2001 From: Nguyen Huy Hoang <24520554@gm.uit.edu.vn> Date: Thu, 26 Mar 2026 23:00:10 +0700 Subject: [PATCH] feat: add `commit.patch` property to expose commit-to-parent diff text Signed-off-by: Nguyen Huy Hoang <181364121+huyhoang171106@users.noreply.github.com> --- git/objects/commit.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/git/objects/commit.py b/git/objects/commit.py index 8c51254a2..71cc70bec 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -196,6 +196,13 @@ def __init__( if gpgsig is not None: self.gpgsig = gpgsig + @property + def patch(self) -> str: + """Textual patch comparing this commit against its first parent.""" + if not self.parents: + return self.repo.git.diff_tree(self.hexsha, root=True, p=True) + return self.repo.git.diff("%s..%s" % (self.parents[0].hexsha, self.hexsha), p=True) + @classmethod def _get_intermediate_items(cls, commit: "Commit") -> Tuple["Commit", ...]: return tuple(commit.parents)