Skip to content

Commit 7b02273

Browse files
authored
Merge pull request #7927 from deveshks/raise-exception-if-rev-empty-git-url
Raise an exception if revision is empty in git url
2 parents 0c30b45 + 59df536 commit 7b02273

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Diff for: news/7402.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reject VCS URLs with an empty revision.

Diff for: src/pip/_internal/vcs/versioncontrol.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pip._vendor import pkg_resources
1212
from pip._vendor.six.moves.urllib import parse as urllib_parse
1313

14-
from pip._internal.exceptions import BadCommand
14+
from pip._internal.exceptions import BadCommand, InstallationError
1515
from pip._internal.utils.compat import samefile
1616
from pip._internal.utils.misc import (
1717
ask_path_exists,
@@ -436,6 +436,12 @@ def get_url_rev_and_auth(cls, url):
436436
rev = None
437437
if '@' in path:
438438
path, rev = path.rsplit('@', 1)
439+
if not rev:
440+
raise InstallationError(
441+
"The URL {!r} has an empty revision (after @) "
442+
"which is not supported. Include a revision after @ "
443+
"or remove @ from the URL.".format(url)
444+
)
439445
url = urllib_parse.urlunsplit((scheme, netloc, path, query, ''))
440446
return url, rev, user_pass
441447

Diff for: tests/unit/test_vcs.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from mock import patch
66
from pip._vendor.packaging.version import parse as parse_version
77

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

294294

295+
@pytest.mark.parametrize('url', [
296+
# Test a URL with revision part as empty.
297+
'git+https://github.com/MyUser/myProject.git@#egg=py_pkg',
298+
])
299+
def test_version_control__get_url_rev_and_auth__no_revision(url):
300+
"""
301+
Test passing a URL to VersionControl.get_url_rev_and_auth() with
302+
empty revision
303+
"""
304+
with pytest.raises(InstallationError) as excinfo:
305+
VersionControl.get_url_rev_and_auth(url)
306+
307+
assert 'an empty revision (after @)' in str(excinfo.value)
308+
309+
295310
@pytest.mark.parametrize('url, expected', [
296311
# Test http.
297312
('bzr+http://bzr.myproject.org/MyProject/trunk/#egg=MyProject',

0 commit comments

Comments
 (0)