Skip to content

Commit 6bfdf93

Browse files
committed
Commit.iter_items: Will not restrict comits to the ones containing changes to paths anymore as it will only append '--' if paths are actually given.
Added unittest to verify this
1 parent 3e14ab5 commit 6bfdf93

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/git/objects/commit.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,13 @@ def iter_items(cls, repo, rev, paths='', **kwargs):
165165
"""
166166
options = {'pretty': 'raw', 'as_process' : True }
167167
options.update(kwargs)
168+
169+
args = list()
170+
if paths:
171+
args.extend(('--', paths))
172+
# END if paths
168173

169-
proc = repo.git.rev_list(rev, '--', paths, **options)
174+
proc = repo.git.rev_list(rev, args, **options)
170175
return cls._iter_from_process_or_stream(repo, proc, True)
171176

172177
def iter_parents(self, paths='', **kwargs):

test/git/test_commit.py

+18
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ def test_traversal(self):
9292
# sha )
9393
assert len(first.parents) == 0
9494

95+
def test_iteration(self):
96+
# we can iterate commits
97+
all_commits = Commit.list_items(self.rorepo, 'master')
98+
assert all_commits
99+
assert all_commits == list(self.rorepo.iter_commits())
100+
101+
# this includes merge commits
102+
mcomit = Commit(self.rorepo, 'd884adc80c80300b4cc05321494713904ef1df2d')
103+
assert mcomit in all_commits
104+
105+
# we can limit the result to paths
106+
ltd_commits = list(self.rorepo.iter_commits(paths='CHANGES'))
107+
assert ltd_commits and len(ltd_commits) < len(all_commits)
108+
109+
# show commits of multiple paths, resulting in a union of commits
110+
less_ltd_commits = list(Commit.iter_items(self.rorepo, 'master', paths=('CHANGES', 'AUTHORS')))
111+
assert len(ltd_commits) < len(less_ltd_commits)
112+
95113

96114
@patch_object(Git, '_call_process')
97115
def test_rev_list_bisect_all(self, git):

0 commit comments

Comments
 (0)