Skip to content

Commit

Permalink
Merge pull request #7927 from deveshks/raise-exception-if-rev-empty-g…
Browse files Browse the repository at this point in the history
…it-url

Raise an exception if revision is empty in git url
  • Loading branch information
pradyunsg authored Apr 1, 2020
2 parents 0c30b45 + 59df536 commit 7b02273
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/7402.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reject VCS URLs with an empty revision.
8 changes: 7 additions & 1 deletion src/pip/_internal/vcs/versioncontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pip._vendor import pkg_resources
from pip._vendor.six.moves.urllib import parse as urllib_parse

from pip._internal.exceptions import BadCommand
from pip._internal.exceptions import BadCommand, InstallationError
from pip._internal.utils.compat import samefile
from pip._internal.utils.misc import (
ask_path_exists,
Expand Down Expand Up @@ -436,6 +436,12 @@ def get_url_rev_and_auth(cls, url):
rev = None
if '@' in path:
path, rev = path.rsplit('@', 1)
if not rev:
raise InstallationError(
"The URL {!r} has an empty revision (after @) "
"which is not supported. Include a revision after @ "
"or remove @ from the URL.".format(url)
)
url = urllib_parse.urlunsplit((scheme, netloc, path, query, ''))
return url, rev, user_pass

Expand Down
17 changes: 16 additions & 1 deletion tests/unit/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from mock import patch
from pip._vendor.packaging.version import parse as parse_version

from pip._internal.exceptions import BadCommand
from pip._internal.exceptions import BadCommand, InstallationError
from pip._internal.utils.misc import hide_url, hide_value
from pip._internal.vcs import make_vcs_requirement_url
from pip._internal.vcs.bazaar import Bazaar
Expand Down Expand Up @@ -292,6 +292,21 @@ def test_version_control__get_url_rev_and_auth__missing_plus(url):
assert 'malformed VCS url' in str(excinfo.value)


@pytest.mark.parametrize('url', [
# Test a URL with revision part as empty.
'git+https://github.com/MyUser/myProject.git@#egg=py_pkg',
])
def test_version_control__get_url_rev_and_auth__no_revision(url):
"""
Test passing a URL to VersionControl.get_url_rev_and_auth() with
empty revision
"""
with pytest.raises(InstallationError) as excinfo:
VersionControl.get_url_rev_and_auth(url)

assert 'an empty revision (after @)' in str(excinfo.value)


@pytest.mark.parametrize('url, expected', [
# Test http.
('bzr+http://bzr.myproject.org/MyProject/trunk/#egg=MyProject',
Expand Down

0 comments on commit 7b02273

Please sign in to comment.