Skip to content
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

Git.check_version() can return incorrect results #4675

Closed
cjerdonek opened this issue Aug 14, 2017 · 3 comments
Closed

Git.check_version() can return incorrect results #4675

cjerdonek opened this issue Aug 14, 2017 · 3 comments
Labels
auto-locked Outdated issues that have been locked by automation type: bug A confirmed bug or unintended behavior

Comments

@cjerdonek
Copy link
Member

cjerdonek commented Aug 14, 2017

While working on PR #4674 for issue #4507, I noticed that the Git class's check_version() method can return incorrect results, leading to pip install -e git+git://... not updating its clone in certain (albeit rare) cases when it needs to.

Specifically, Git.check_version(dest, rev_options) isn't supposed to return True if given a branch or tag. For example, its docstring says:

Compare the current sha to the ref. ref may be a branch or tag name ... This means that a branch or tag will never compare as True. So this ultimately only matches against exact shas.

However, with the way it's currently written, the method can return True on a branch or tag since it does prefix matching instead of checking for an exact match. For example, given a repo with HEAD:

10d02d33e110f0b18e628ab8cab028a0a219773c

if you pass the tag name 10, then check_version('/path', '10') will return True even though 10 isn't a commit hash. This can prevent pip from checking the remote repo for new tags / commits / etc.

Related to this, I also noticed that test_git_check_version() has a bug because it is incorrectly passing a ref in each call to check_version() instead of a list containing the ref.

This means the following test case would incorrectly pass when it shouldn't (the other cases are "accidentally" working):

@pytest.mark.parametrize('ref,result', (
    ('5547fa909e83df8bd743d3978d6667497983a4b7', True),
    ('5547fa909', True),
    ('5678', True),  # This would incorrectly pass since it uses "5" as the ref.
    ('abc123', False),
    ('foo', False),
))
def test_git_check_version(git, ref, result):
    assert git.check_version('foo', ref) is result

I posted a fix for both of these issues in PR #4674, which I'm going to break into smaller PR's. In that PR, I also simplified the API for check_version() to make it harder to use incorrectly, like in both of the cases above.

@cjerdonek
Copy link
Member Author

I posted PR #4676 to address this.

@pradyunsg pradyunsg added the type: bug A confirmed bug or unintended behavior label Aug 20, 2017
@cjerdonek
Copy link
Member Author

PR #4676 is now ready for review.

xavfernandez added a commit that referenced this issue Oct 5, 2017
@xavfernandez
Copy link
Member

Closed by #4676

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants