summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Trier <mtrier@gmail.com>2008-12-16 19:44:49 -0500
committerMichael Trier <mtrier@gmail.com>2008-12-16 20:53:04 -0500
commite4582f805156095604fe07e71195cd9aa43d7a34 (patch)
tree78eb4778aed234c96affc2d8eeaf8f935499bc86
parent79cfe05054de8a31758eb3de74532ed422c8da27 (diff)
downloadgitpython-e4582f805156095604fe07e71195cd9aa43d7a34.tar.gz
fixed Commit.stats retrieval for parentless commits in bare repos
(cherry picked from commit 88852ed7bcde4f4b18c1ae8b6fba7f3fab8e9bf5)
-rw-r--r--CHANGES3
-rw-r--r--lib/git/commit.py8
-rw-r--r--test/fixtures/diff_tree_numstat_root3
-rw-r--r--test/git/test_commit.py6
4 files changed, 13 insertions, 7 deletions
diff --git a/CHANGES b/CHANGES
index 9a1baa62..0d236f3d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -24,6 +24,9 @@ Commit
the first line) and a new property ``Commit.summary`` contains the first
line of the commit message.
+* Fixed a failure when trying to lookup the stats of a parentless commit from
+ a bare repo.
+
Diff
----
* The diff parser is now far faster and also addresses a bug where
diff --git a/lib/git/commit.py b/lib/git/commit.py
index 091cf78c..f8c7e61f 100644
--- a/lib/git/commit.py
+++ b/lib/git/commit.py
@@ -165,7 +165,7 @@ class Commit(LazyMixin):
message = '\n'.join(messages)
- commits.append(Commit(repo, id=id, parents=parents, tree=tree, author=author, authored_date=authored_date,
+ commits.append(Commit(repo, id=id, parents=parents, tree=tree, author=author, authored_date=authored_date,
committer=committer, committed_date=committed_date, message=message))
return commits
@@ -224,11 +224,11 @@ class Commit(LazyMixin):
@property
def stats(self):
if not self.parents:
- text = self.repo.git.diff(self.id, '--', numstat=True)
+ text = self.repo.git.diff_tree(self.id, '--', numstat=True, root=True)
text2 = ""
- for line in text.splitlines():
+ for line in text.splitlines()[1:]:
(insertions, deletions, filename) = line.split("\t")
- text2 += "%s\t%s\t%s\n" % (deletions, insertions, filename)
+ text2 += "%s\t%s\t%s\n" % (insertions, deletions, filename)
text = text2
else:
text = self.repo.git.diff(self.parents[0].id, self.id, '--', numstat=True)
diff --git a/test/fixtures/diff_tree_numstat_root b/test/fixtures/diff_tree_numstat_root
new file mode 100644
index 00000000..bebdaa6d
--- /dev/null
+++ b/test/fixtures/diff_tree_numstat_root
@@ -0,0 +1,3 @@
+634396b2f541a9f2d58b00be1a07f0c358b999b3
+18 29 a.txt
+5 0 b.txt
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index da7236c8..4af13d80 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -129,7 +129,7 @@ class TestCommit(object):
assert_equal(True, diffs[5].new_file)
assert_true(git.called)
- assert_equal(git.call_args, (('diff', '-M',
+ assert_equal(git.call_args, (('diff', '-M',
'038af8c329ef7c1bae4568b98bd5c58510465493',
'91169e1f5fa4de2eaea3f176461f5dc784796769',
), {'full_index': True}))
@@ -190,7 +190,7 @@ class TestCommit(object):
@patch_object(Git, '_call_process')
def test_stats(self, git):
- git.return_value = fixture('diff_numstat')
+ git.return_value = fixture('diff_tree_numstat_root')
commit = Commit(self.repo, id='634396b2f541a9f2d58b00be1a07f0c358b999b3')
commit.__bake_it__()
@@ -201,7 +201,7 @@ class TestCommit(object):
assert_equal(["a.txt", "b.txt"], keys)
assert_true(git.called)
- assert_equal(git.call_args, (('diff', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '--'), {'numstat': True}))
+ assert_equal(git.call_args, (('diff_tree', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '--'), {'numstat': True, 'root': True }))
@patch_object(Git, '_call_process')
def test_rev_list_bisect_all(self, git):