Skip to content

Commit e827695

Browse files
committed
Fix AttributeError when searching a remote by name
Running code like `'origin' in git.Repo('path/to/existing/repository').remotes` raises an AttributeError instead of returning a boolean. This commit fixes that behaviour by catching the error when doing an identity match on `IterableList`.
1 parent 1f66e25 commit e827695

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ Contributors are:
2929
-Tim Swast <swast _at_ google.com>
3030
-William Luc Ritchie
3131
-David Host <hostdm _at_ outlook.com>
32+
-César Izurieta <cesar _at_ caih.org>
3233

3334
Portions derived from other open source works and are clearly marked.

git/util.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,12 @@ def __init__(self, id_attr, prefix=''):
864864

865865
def __contains__(self, attr):
866866
# first try identity match for performance
867-
rval = list.__contains__(self, attr)
868-
if rval:
869-
return rval
867+
try:
868+
rval = list.__contains__(self, attr)
869+
if rval:
870+
return rval
871+
except (AttributeError, TypeError):
872+
pass
870873
# END handle match
871874

872875
# otherwise make a full name search

0 commit comments

Comments
 (0)