2

I am trying to print the "diff" object as shown below. I am expecting an output similar to git show , but I am not getting the same. How do I achieve this? Thanks.

import pygit2
repo=pygit2.Repository('/home/repository')

t0=repo.revparse_single('HEAD')
t1=repo.revparse_single('HEAD^')


>>> repo.diff(t0,t1)
<_pygit2.Diff object at 0x7fc46eeb0470>
>>> out=repo.diff(t0,t1)
>>> print out
<_pygit2.Diff object at 0x7fc46eeb0410>
>>> 
Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
Zack
  • 2,078
  • 10
  • 33
  • 58

1 Answers1

3

Let's check the documentation for pygit2:

$ pydoc pygit2.Diff
 |  ----------------------------------
 |  Data descriptors defined here:
 |  
 |  patch
 |      Patch diff string.

Okay, so let's try that:

>>> out=repo.diff(t0,t1)
>>> print out
<_pygit2.Diff object at 0x7fc46eeb0410>
>>> print out.patch
diff --git a/file1 b/file1
index 10952f3..66ed2b8 100644
--- a/file1
+++ b/file1
@@ -1,5 +1,6 @@
 DIR_COLORS
 DIR_COLORS.256color
+DIR_COLORS.lightbgcolor
 GREP_COLORS
 X11
 adjtime

Seems to work.

larsks
  • 277,717
  • 41
  • 399
  • 399