Skip to content

Fix AttributeError when searching a remote by name #862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2019

Conversation

cesarizu
Copy link
Contributor

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.

Minimum test case with version 2.1.11:

>>> 'origin' in git.Repo('path/to/existing/repository').remotes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cesar/.local/lib/python3.7/site-packages/git/util.py", line 867, in __contains__
    rval = list.__contains__(self, attr)
  File "/home/cesar/.local/lib/python3.7/site-packages/git/remote.py", line 451, in __eq__
    return self.name == other.name
AttributeError: 'str' object has no attribute 'name'

Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a single test fails, and I would trust that it is indeed genuine.
Maybe you have some ideas why that would be.
Thanks for your help!

@cesarizu
Copy link
Contributor Author

I just tried that same test on master and I still see the failure. Also, it doesn't touch the IterableList#__contains__ function (modified in this PR) at all, so it seems unrelated. Or am I missing something here?

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`.
@codecov-io
Copy link

Codecov Report

Merging #862 into master will increase coverage by 1.06%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #862      +/-   ##
==========================================
+ Coverage    93.6%   94.66%   +1.06%     
==========================================
  Files          59       59              
  Lines        9769     9389     -380     
==========================================
- Hits         9144     8888     -256     
+ Misses        625      501     -124
Impacted Files Coverage Δ
git/index/util.py 90.69% <0%> (-0.61%) ⬇️
git/index/typ.py 96.82% <0%> (-0.58%) ⬇️
git/objects/tag.py 81.08% <0%> (-0.5%) ⬇️
git/test/test_config.py 98.33% <0%> (-0.47%) ⬇️
git/objects/tree.py 59.64% <0%> (-0.36%) ⬇️
git/objects/base.py 95.83% <0%> (-0.33%) ⬇️
git/refs/tag.py 96.66% <0%> (-0.31%) ⬇️
git/test/test_remote.py 97.54% <0%> (-0.3%) ⬇️
git/refs/reference.py 95.74% <0%> (-0.26%) ⬇️
git/refs/symbolic.py 96.11% <0%> (-0.14%) ⬇️
... and 29 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e93ffe1...dc050e5. Read the comment docs.

@cesarizu
Copy link
Contributor Author

In any case, I've just rebased the branch and it's all green now.

@Byron Byron added this to the v2.1.12 - Bugfixes milestone Jul 21, 2019
@Byron Byron merged commit bd86c87 into gitpython-developers:master Jul 21, 2019
@Byron
Copy link
Member

Byron commented Jul 21, 2019

Thanks a bunch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants