Give priority to git remote named origin in pip freeze (#3708)

This commit is contained in:
Stéphane Bidoul (ACSONE) 2016-05-21 14:12:37 +02:00 committed by Donald Stufft
parent 231178fef5
commit ce76f2d3e6
3 changed files with 63 additions and 2 deletions

View File

@ -5,6 +5,9 @@
* Fix the build on systems with symlinked /tmp directory for custom
builds such as numpy.
* Fix regression in pip freeze: when there is more than one git remote,
priority is given to the remote named origin (:issue:`3616`)
**8.1.2 (2016-05-10)**

View File

@ -139,8 +139,13 @@ class Git(VersionControl):
remotes = self.run_command(
['config', '--get-regexp', 'remote\..*\.url'],
show_stdout=False, cwd=location)
first_remote = remotes.splitlines()[0]
url = first_remote.split(' ')[1]
remotes = remotes.splitlines()
found_remote = remotes[0]
for remote in remotes:
if remote.startswith('remote.origin.url '):
found_remote = remote
break
url = found_remote.split(' ')[1]
return url.strip()
def get_revision(self, location):

View File

@ -193,6 +193,59 @@ def test_freeze_git_clone_srcdir(script, tmpdir):
_check_output(result.stdout, expected)
@pytest.mark.git
def test_freeze_git_remote(script, tmpdir):
"""
Test freezing a Git clone.
"""
# Returns path to a generated package called "version_pkg"
pkg_version = _create_test_package(script)
result = script.run(
'git', 'clone', pkg_version, 'pip-test-package',
expect_stderr=True,
)
repo_dir = script.scratch_path / 'pip-test-package'
result = script.run(
'python', 'setup.py', 'develop',
cwd=repo_dir,
expect_stderr=True,
)
origin_remote = pkg_version
other_remote = pkg_version + '-other'
# check frozen remote after clone
result = script.pip('freeze', expect_stderr=True)
expected = textwrap.dedent(
"""
...-e git+{remote}@...#egg=version_pkg
...
"""
).format(remote=origin_remote).strip()
_check_output(result.stdout, expected)
# check frozen remote when there is no remote named origin
script.run('git', 'remote', 'remove', 'origin', cwd=repo_dir)
script.run('git', 'remote', 'add', 'other', other_remote, cwd=repo_dir)
result = script.pip('freeze', expect_stderr=True)
expected = textwrap.dedent(
"""
...-e git+{remote}@...#egg=version_pkg
...
"""
).format(remote=other_remote).strip()
_check_output(result.stdout, expected)
# when there are more than one origin, priority is given to the
# remote named origin
script.run('git', 'remote', 'add', 'origin', origin_remote, cwd=repo_dir)
result = script.pip('freeze', expect_stderr=True)
expected = textwrap.dedent(
"""
...-e git+{remote}@...#egg=version_pkg
...
"""
).format(remote=origin_remote).strip()
_check_output(result.stdout, expected)
@pytest.mark.mercurial
def test_freeze_mercurial_clone(script, tmpdir):
"""