Skip to content

Commit a5e607e

Browse files
committed
fix(iter-commit): ambiguous argument error
In repositories like > git branch -a * test > ls test `repo.iter_commits` failed due to an ambigous argument (`'git rev-list test`). Now this cannot happen anymore. fixes #264
1 parent 630d030 commit a5e607e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

git/objects/commit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,12 @@ def iter_items(cls, repo, rev, paths='', **kwargs):
189189
if 'pretty' in kwargs:
190190
raise ValueError("--pretty cannot be used as parsing expects single sha's only")
191191
# END handle pretty
192-
args = list()
192+
193+
# use -- in any case, to prevent possibility of ambiguous arguments
194+
# see https://github.com/gitpython-developers/GitPython/issues/264
195+
args = ['--']
193196
if paths:
194-
args.extend(('--', paths))
197+
args.extend((paths, ))
195198
# END if paths
196199

197200
proc = repo.git.rev_list(rev, args, as_process=True, **kwargs)

git/test/test_commit.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@
1919
Actor,
2020
)
2121
from gitdb import IStream
22+
from gitdb.test.lib import with_rw_directory
2223
from git.compat import (
2324
string_types,
2425
text_type
2526
)
27+
from git import Repo
28+
from git.repo.fun import touch
2629

2730
from io import BytesIO
2831
import time
2932
import sys
3033
import re
34+
import os
3135

3236

3337
def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False):
@@ -219,6 +223,15 @@ def test_rev_list_bisect_all(self):
219223
for sha1, commit in zip(expected_ids, commits):
220224
assert_equal(sha1, commit.hexsha)
221225

226+
@with_rw_directory
227+
def test_ambiguous_arg_iteration(self, rw_dir):
228+
rw_repo = Repo.init(os.path.join(rw_dir, 'test_ambiguous_arg'))
229+
path = os.path.join(rw_repo.working_tree_dir, 'master')
230+
touch(path)
231+
rw_repo.index.add([path])
232+
rw_repo.index.commit('initial commit')
233+
list(rw_repo.iter_commits(rw_repo.head.ref)) # should fail unless bug is fixed
234+
222235
def test_count(self):
223236
assert self.rorepo.tag('refs/tags/0.1.5').commit.count() == 143
224237

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy