fixed Commit.stats retrieval for parentless commits in bare repos · gitpython-developers/GitPython@e4582f8 · GitHub
Skip to content

Commit e4582f8

Browse files
committed
fixed Commit.stats retrieval for parentless commits in bare repos
(cherry picked from commit 88852ed7bcde4f4b18c1ae8b6fba7f3fab8e9bf5)
1 parent 79cfe05 commit e4582f8

4 files changed

Lines changed: 13 additions & 7 deletions

File tree

CHANGES

Lines changed: 3 additions & 0 deletions

lib/git/commit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def list_from_string(cls, repo, text):
165165

166166
message = '\n'.join(messages)
167167

168-
commits.append(Commit(repo, id=id, parents=parents, tree=tree, author=author, authored_date=authored_date,
168+
commits.append(Commit(repo, id=id, parents=parents, tree=tree, author=author, authored_date=authored_date,
169169
committer=committer, committed_date=committed_date, message=message))
170170

171171
return commits
@@ -224,11 +224,11 @@ def diffs(self):
224224
@property
225225
def stats(self):
226226
if not self.parents:
227-
text = self.repo.git.diff(self.id, '--', numstat=True)
227+
text = self.repo.git.diff_tree(self.id, '--', numstat=True, root=True)
228228
text2 = ""
229-
for line in text.splitlines():
229+
for line in text.splitlines()[1:]:
230230
(insertions, deletions, filename) = line.split("\t")
231-
text2 += "%s\t%s\t%s\n" % (deletions, insertions, filename)
231+
text2 += "%s\t%s\t%s\n" % (insertions, deletions, filename)
232232
text = text2
233233
else:
234234
text = self.repo.git.diff(self.parents[0].id, self.id, '--', numstat=True)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
634396b2f541a9f2d58b00be1a07f0c358b999b3
2+
18 29 a.txt
3+
5 0 b.txt

test/git/test_commit.py

Lines changed: 3 additions & 3 deletions

0 commit comments

Comments
 (0)