Skip to content

Commit

Permalink
Fix inheritance issue at commit.iter_items
Browse files Browse the repository at this point in the history
The iterator used to yield Commit() objects, which does not play well
with inheritance. Yield cls() instead.

Signed-off-by: Yuri Volchkov <yuri@volch.org>
  • Loading branch information
Yuri Volchkov authored and yvolchkov committed Feb 5, 2021
1 parent 3c19a6e commit af86f05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream):
# END handle extra info

assert len(hexsha) == 40, "Invalid line: %s" % hexsha
yield Commit(repo, hex_to_bin(hexsha))
yield cls(repo, hex_to_bin(hexsha))
# END for each line in stream
# TODO: Review this - it seems process handling got a bit out of control
# due to many developers trying to fix the open file handles issue
Expand Down
7 changes: 7 additions & 0 deletions test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ def test_iteration(self):
less_ltd_commits = list(Commit.iter_items(self.rorepo, 'master', paths=('CHANGES', 'AUTHORS')))
assert len(ltd_commits) < len(less_ltd_commits)

class Child(Commit):
def __init__(self, *args, **kwargs):
super(Child, self).__init__(*args, **kwargs)

child_commits = list(Child.iter_items(self.rorepo, 'master', paths=('CHANGES', 'AUTHORS')))
assert type(child_commits[0]) == Child

def test_iter_items(self):
# pretty not allowed
self.assertRaises(ValueError, Commit.iter_items, self.rorepo, 'master', pretty="raw")
Expand Down

0 comments on commit af86f05

Please sign in to comment.