66
77import re
88import objects .blob as blob
9-
9+ from errors import GitCommandError
1010
1111class Diffable (object ):
1212 """
@@ -26,15 +26,17 @@ class Diffable(object):
2626 class Index (object ):
2727 pass
2828
29- def diff (self , other = None , paths = None , create_patch = False , ** kwargs ):
29+ def diff (self , other = Index , paths = None , create_patch = False , ** kwargs ):
3030 """
3131 Creates diffs between two items being trees, trees and index or an
3232 index and the working tree.
3333
3434 ``other``
3535 Is the item to compare us with.
3636 If None, we will be compared to the working tree.
37- If Index ( type ), it will be compared against the index
37+ If Index ( type ), it will be compared against the index.
38+ It defaults to Index to assure the method will not by-default fail
39+ on bare repositories.
3840
3941 ``paths``
4042 is a list of paths or a single path to limit the diff to.
@@ -53,7 +55,10 @@ def diff(self, other=None, paths=None, create_patch=False, **kwargs):
5355 git.DiffIndex
5456
5557 Note
56- Rename detection will only work if create_patch is True
58+ Rename detection will only work if create_patch is True.
59+
60+ On a bare repository, 'other' needs to be provided as Index or as
61+ as Tree/Commit, or a git command error will occour
5762 """
5863 args = list (self ._diff_args [:])
5964 args .append ( "--abbrev=40" ) # we need full shas
@@ -87,7 +92,13 @@ def diff(self, other=None, paths=None, create_patch=False, **kwargs):
8792 diff_method = Diff ._index_from_raw_format
8893 if create_patch :
8994 diff_method = Diff ._index_from_patch_format
90- return diff_method (self .repo , proc .stdout )
95+ index = diff_method (self .repo , proc .stdout )
96+
97+ status = proc .wait ()
98+ if status != 0 :
99+ raise GitCommandError ("git-diff" , status , proc .stderr )
100+
101+ return index
91102
92103
93104class DiffIndex (list ):
0 commit comments