summaryrefslogtreecommitdiff
path: root/lib/git/diff.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-18 17:09:13 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-18 17:09:13 +0200
commit9840afda82fafcc3eaf52351c64e2cfdb8962397 (patch)
treef879f2e798ad2d5345d7eca7da76db7c00181481 /lib/git/diff.py
parent225999e9442c746333a8baa17a6dbf7341c135ca (diff)
downloadgitpython-9840afda82fafcc3eaf52351c64e2cfdb8962397.tar.gz
diff method now checks for git-diff errrs that can easily occour if the repository is bare and if there is no index or second tree specified
Diffstat (limited to 'lib/git/diff.py')
-rw-r--r--lib/git/diff.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/git/diff.py b/lib/git/diff.py
index 1774597a..9b884502 100644
--- a/lib/git/diff.py
+++ b/lib/git/diff.py
@@ -6,7 +6,7 @@
import re
import objects.blob as blob
-
+from errors import GitCommandError
class Diffable(object):
"""
@@ -26,7 +26,7 @@ class Diffable(object):
class Index(object):
pass
- def diff(self, other=None, paths=None, create_patch=False, **kwargs):
+ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
"""
Creates diffs between two items being trees, trees and index or an
index and the working tree.
@@ -34,7 +34,9 @@ class Diffable(object):
``other``
Is the item to compare us with.
If None, we will be compared to the working tree.
- If Index ( type ), it will be compared against the index
+ If Index ( type ), it will be compared against the index.
+ It defaults to Index to assure the method will not by-default fail
+ on bare repositories.
``paths``
is a list of paths or a single path to limit the diff to.
@@ -53,7 +55,10 @@ class Diffable(object):
git.DiffIndex
Note
- Rename detection will only work if create_patch is True
+ Rename detection will only work if create_patch is True.
+
+ On a bare repository, 'other' needs to be provided as Index or as
+ as Tree/Commit, or a git command error will occour
"""
args = list(self._diff_args[:])
args.append( "--abbrev=40" ) # we need full shas
@@ -87,7 +92,13 @@ class Diffable(object):
diff_method = Diff._index_from_raw_format
if create_patch:
diff_method = Diff._index_from_patch_format
- return diff_method(self.repo, proc.stdout)
+ index = diff_method(self.repo, proc.stdout)
+
+ status = proc.wait()
+ if status != 0:
+ raise GitCommandError("git-diff", status, proc.stderr )
+
+ return index
class DiffIndex(list):