Skip to content

Commit 4e34960

Browse files
author
Nguyen Huy Hoang
committed
feat: add commit.patch property to expose commit-to-parent diff text
Signed-off-by: Nguyen Huy Hoang <181364121+huyhoang171106@users.noreply.github.com>
1 parent becccc8 commit 4e34960

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

git/objects/commit.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ def __init__(
196196
if gpgsig is not None:
197197
self.gpgsig = gpgsig
198198

199+
@property
200+
def patch(self) -> str:
201+
"""Textual patch comparing this commit against its first parent."""
202+
if not self.parents:
203+
return self.repo.git.diff_tree(self.hexsha, root=True, p=True)
204+
return self.repo.git.diff("%s..%s" % (self.parents[0].hexsha, self.hexsha), p=True)
205+
199206
@classmethod
200207
def _get_intermediate_items(cls, commit: "Commit") -> Tuple["Commit", ...]:
201208
return tuple(commit.parents)

0 commit comments

Comments
 (0)