summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Stufft <donald@stufft.io>2015-03-16 17:38:49 -0400
committerDonald Stufft <donald@stufft.io>2015-03-16 17:38:49 -0400
commitab3f2edd5e1e038587547d4c7c8a04b042ba2bdc (patch)
tree2f3b36487b13afde501606277a450ab8b8ac5824
parent598d5bad294f711e53bf69466615ca9f9640f255 (diff)
downloadpip-revert-2547-revert-2513-ssh_and_commit_support.tar.gz
Revert "Revert "#2414: parse SSH repositories url with a commit hash""revert-2547-revert-2513-ssh_and_commit_support
-rw-r--r--pip/vcs/__init__.py14
-rw-r--r--pip/vcs/git.py2
-rw-r--r--tests/unit/test_vcs.py34
3 files changed, 47 insertions, 3 deletions
diff --git a/pip/vcs/__init__.py b/pip/vcs/__init__.py
index 96cb1319f..b9a94669e 100644
--- a/pip/vcs/__init__.py
+++ b/pip/vcs/__init__.py
@@ -144,9 +144,17 @@ class VersionControl(object):
url = self.url.split('+', 1)[1]
scheme, netloc, path, query, frag = urllib_parse.urlsplit(url)
rev = None
- if '@' in path:
- path, rev = path.rsplit('@', 1)
- url = urllib_parse.urlunsplit((scheme, netloc, path, query, ''))
+ if scheme == 'ssh' and not path: # Fix urllib_parse parsing
+ url_splitted = url.split('@')
+ if len(url_splitted) == 3:
+ url = '%s@%s' % (url_splitted[0], url_splitted[1])
+ rev = url_splitted[2].split('#')[0]
+ assert len(url_splitted) < 4,\
+ "You can't have more than two @ in VCS url."
+ else:
+ if '@' in path:
+ path, rev = path.rsplit('@', 1)
+ url = urllib_parse.urlunsplit((scheme, netloc, path, query, ''))
return url, rev
def get_info(self, location):
diff --git a/pip/vcs/git.py b/pip/vcs/git.py
index d575f148a..efb8b2869 100644
--- a/pip/vcs/git.py
+++ b/pip/vcs/git.py
@@ -195,6 +195,8 @@ class Git(VersionControl):
url = url.replace('ssh://', '')
else:
url, rev = super(Git, self).get_url_rev()
+ # For explicit SSH URLs, remove 'ssh://' to clone
+ url = url.replace('ssh://', '')
return url, rev
diff --git a/tests/unit/test_vcs.py b/tests/unit/test_vcs.py
index 8b7e6e8ea..59de98bd9 100644
--- a/tests/unit/test_vcs.py
+++ b/tests/unit/test_vcs.py
@@ -39,6 +39,40 @@ def test_git_get_src_requirements():
])
+def test_git_urls():
+ """
+ Test git url support.
+
+ SSH has special handling.
+ """
+ https_repo = Git(
+ url='git+https://github.com/Eyepea/pip.git'
+ '@8cf54fff31b650847e0cddc2cd2951c34e0b4822#egg=pip'
+ )
+ implicit_ssh_repo = Git(
+ url='git+git@github.com:Eyepea/pip.git'
+ '@8cf54fff31b650847e0cddc2cd2951c34e0b4822#egg=pip'
+ )
+
+ explicit_ssh_repo = Git(
+ url='git+ssh://git@github.com:Eyepea/pip.git'
+ '@8cf54fff31b650847e0cddc2cd2951c34e0b4822#egg=pip'
+ )
+
+ assert https_repo.get_url_rev() == (
+ 'https://github.com/Eyepea/pip.git',
+ '8cf54fff31b650847e0cddc2cd2951c34e0b4822',
+ )
+ assert implicit_ssh_repo.get_url_rev() == (
+ 'git@github.com:Eyepea/pip.git',
+ '8cf54fff31b650847e0cddc2cd2951c34e0b4822',
+ )
+ assert explicit_ssh_repo.get_url_rev() == (
+ 'git@github.com:Eyepea/pip.git',
+ '8cf54fff31b650847e0cddc2cd2951c34e0b4822',
+ )
+
+
def test_translate_egg_surname():
vc = VersionControl()
assert vc.translate_egg_surname("foo") == "foo"