mirror of https://github.com/pypa/pip
Merge pull request #6001 from cjerdonek/rename-and-test-vcs-get-url
Test and rename Git.get_url()
This commit is contained in:
commit
313d571c82
|
@ -327,7 +327,7 @@ class VersionControl(object):
|
|||
|
||||
rev_display = rev_options.to_display()
|
||||
if self.is_repository_directory(dest):
|
||||
existing_url = self.get_url(dest)
|
||||
existing_url = self.get_remote_url(dest)
|
||||
if self.compare_urls(existing_url, url):
|
||||
logger.debug(
|
||||
'%s in %s exists, and has correct URL (%s)',
|
||||
|
@ -419,7 +419,7 @@ class VersionControl(object):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_url(self, location):
|
||||
def get_remote_url(self, location):
|
||||
"""
|
||||
Return the url used at location
|
||||
"""
|
||||
|
|
|
@ -75,7 +75,7 @@ class Bazaar(VersionControl):
|
|||
url = 'bzr+' + url
|
||||
return url, rev, user_pass
|
||||
|
||||
def get_url(self, location):
|
||||
def get_remote_url(self, location):
|
||||
urls = self.run_command(['info'], show_stdout=False, cwd=location)
|
||||
for line in urls.splitlines():
|
||||
line = line.strip()
|
||||
|
@ -95,7 +95,7 @@ class Bazaar(VersionControl):
|
|||
return revision.splitlines()[-1]
|
||||
|
||||
def get_src_requirement(self, location, project_name):
|
||||
repo = self.get_url(location)
|
||||
repo = self.get_remote_url(location)
|
||||
if not repo:
|
||||
return None
|
||||
if not repo.lower().startswith('bzr:'):
|
||||
|
|
|
@ -243,7 +243,7 @@ class Git(VersionControl):
|
|||
#: update submodules
|
||||
self.update_submodules(dest)
|
||||
|
||||
def get_url(self, location):
|
||||
def get_remote_url(self, location):
|
||||
"""Return URL of the first remote encountered."""
|
||||
remotes = self.run_command(
|
||||
['config', '--get-regexp', r'remote\..*\.url'],
|
||||
|
@ -294,7 +294,7 @@ class Git(VersionControl):
|
|||
return os.path.relpath(location, root_dir)
|
||||
|
||||
def get_src_requirement(self, location, project_name):
|
||||
repo = self.get_url(location)
|
||||
repo = self.get_remote_url(location)
|
||||
if not repo.lower().startswith('git:'):
|
||||
repo = 'git+' + repo
|
||||
current_rev = self.get_revision(location)
|
||||
|
|
|
@ -64,7 +64,7 @@ class Mercurial(VersionControl):
|
|||
cmd_args = ['update', '-q'] + rev_options.to_args()
|
||||
self.run_command(cmd_args, cwd=dest)
|
||||
|
||||
def get_url(self, location):
|
||||
def get_remote_url(self, location):
|
||||
url = self.run_command(
|
||||
['showconfig', 'paths.default'],
|
||||
show_stdout=False, cwd=location).strip()
|
||||
|
@ -85,7 +85,7 @@ class Mercurial(VersionControl):
|
|||
return current_rev_hash
|
||||
|
||||
def get_src_requirement(self, location, project_name):
|
||||
repo = self.get_url(location)
|
||||
repo = self.get_remote_url(location)
|
||||
if not repo.lower().startswith('hg:'):
|
||||
repo = 'hg+' + repo
|
||||
current_rev_hash = self.get_revision_hash(location)
|
||||
|
|
|
@ -131,7 +131,7 @@ class Subversion(VersionControl):
|
|||
|
||||
return extra_args
|
||||
|
||||
def get_url(self, location):
|
||||
def get_remote_url(self, location):
|
||||
# In cases where the source is in a subdirectory, not alongside
|
||||
# setup.py we have to look up in the location until we find a real
|
||||
# setup.py
|
||||
|
@ -196,7 +196,7 @@ class Subversion(VersionControl):
|
|||
return url, rev
|
||||
|
||||
def get_src_requirement(self, location, project_name):
|
||||
repo = self.get_url(location)
|
||||
repo = self.get_remote_url(location)
|
||||
if repo is None:
|
||||
return None
|
||||
repo = 'svn+' + repo
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import pytest
|
||||
|
||||
from tests.lib import (
|
||||
_change_test_package_version, _create_test_package, pyversion,
|
||||
_change_test_package_version, _create_test_package, _test_path_to_file_url,
|
||||
pyversion,
|
||||
)
|
||||
from tests.lib.git_submodule_helpers import (
|
||||
_change_test_package_submodule, _create_test_package_with_submodule,
|
||||
|
@ -70,9 +71,9 @@ def _make_version_pkg_url(path, rev=None):
|
|||
containing the version_pkg package.
|
||||
rev: an optional revision to install like a branch name, tag, or SHA.
|
||||
"""
|
||||
path = path.abspath.replace('\\', '/')
|
||||
file_url = _test_path_to_file_url(path)
|
||||
url_rev = '' if rev is None else '@{}'.format(rev)
|
||||
url = 'git+file://{}{}#egg=version_pkg'.format(path, url_rev)
|
||||
url = 'git+{}{}#egg=version_pkg'.format(file_url, url_rev)
|
||||
|
||||
return url
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import pytest
|
|||
|
||||
from pip._internal.utils.temp_dir import TempDirectory
|
||||
from pip._internal.vcs.git import Git
|
||||
from tests.lib import _create_test_package
|
||||
from tests.lib import _create_test_package, _test_path_to_file_url
|
||||
|
||||
|
||||
def get_head_sha(script, dest):
|
||||
|
@ -70,6 +70,22 @@ def test_git_work_tree_ignored():
|
|||
git.run_command(['status', temp_dir], extra_environ=env, cwd=temp_dir)
|
||||
|
||||
|
||||
def test_get_remote_url(script, tmpdir):
|
||||
source_dir = tmpdir / 'source'
|
||||
source_dir.mkdir()
|
||||
source_url = _test_path_to_file_url(source_dir)
|
||||
|
||||
source_dir = str(source_dir)
|
||||
script.run('git', 'init', cwd=source_dir)
|
||||
do_commit(script, source_dir)
|
||||
|
||||
repo_dir = str(tmpdir / 'repo')
|
||||
script.run('git', 'clone', source_url, repo_dir, expect_stderr=True)
|
||||
|
||||
remote_url = Git().get_remote_url(repo_dir)
|
||||
assert remote_url == source_url
|
||||
|
||||
|
||||
def test_get_branch(script, tmpdir):
|
||||
repo_dir = str(tmpdir)
|
||||
script.run('git', 'init', cwd=repo_dir)
|
||||
|
|
|
@ -38,6 +38,16 @@ def path_to_url(path):
|
|||
return 'file://' + url
|
||||
|
||||
|
||||
def _test_path_to_file_url(path):
|
||||
"""
|
||||
Convert a test Path to a "file://" URL.
|
||||
|
||||
Args:
|
||||
path: a tests.lib.path.Path object.
|
||||
"""
|
||||
return 'file://' + path.abspath.replace('\\', '/')
|
||||
|
||||
|
||||
def create_file(path, contents=None):
|
||||
"""Create a file on the path, with the given contents
|
||||
"""
|
||||
|
|
|
@ -75,7 +75,7 @@ def git():
|
|||
git_url = 'https://github.com/pypa/pip-test-package'
|
||||
sha = '5547fa909e83df8bd743d3978d6667497983a4b7'
|
||||
git = Git()
|
||||
git.get_url = Mock(return_value=git_url)
|
||||
git.get_remote_url = Mock(return_value=git_url)
|
||||
git.get_revision = Mock(return_value=sha)
|
||||
return git
|
||||
|
||||
|
|
Loading…
Reference in New Issue