From 8d963638825aceeaa06bf350685e4ac1d4cccd12 Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Fri, 29 Sep 2017 17:30:30 -0500 Subject: [PATCH] Don't assume master branch exists when reinstalling editable package from Git (#4450) * Add failing test * Don't assume master branch is default * Don't expect output to stderr * Use the 'short ref' instead of the 'full ref' --- news/4448.bugfix | 2 ++ src/pip/_internal/vcs/git.py | 2 +- tests/functional/test_install_vcs.py | 29 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 news/4448.bugfix diff --git a/news/4448.bugfix b/news/4448.bugfix new file mode 100644 index 00000000000..28088dd6301 --- /dev/null +++ b/news/4448.bugfix @@ -0,0 +1,2 @@ +Reinstalling an editable package from Git no longer assumes that the ``master`` +branch exists. diff --git a/src/pip/_internal/vcs/git.py b/src/pip/_internal/vcs/git.py index 6262f2729de..b7b12817772 100644 --- a/src/pip/_internal/vcs/git.py +++ b/src/pip/_internal/vcs/git.py @@ -132,7 +132,7 @@ def obtain(self, dest): rev_options = [rev] rev_display = ' (to %s)' % rev else: - rev_options = ['origin/master'] + rev_options = ['origin/HEAD'] rev_display = '' if self.check_destination(dest, url, rev_options, rev_display): logger.info( diff --git a/tests/functional/test_install_vcs.py b/tests/functional/test_install_vcs.py index d8175331e7d..4845f91ad1f 100644 --- a/tests/functional/test_install_vcs.py +++ b/tests/functional/test_install_vcs.py @@ -253,3 +253,32 @@ def test_git_works_with_editable_non_origin_repo(script): assert "Error when trying to get requirement" in result.stderr assert "Could not determine repository location" in result.stdout assert "version-pkg==0.1" in result.stdout + + +@pytest.mark.network +def test_reinstalling_works_with_editible_non_master_branch(script): + """ + Reinstalling an editable installation should not assume that the "master" + branch exists. See https://github.com/pypa/pip/issues/4448. + """ + version_pkg_path = _create_test_package(script) + + # Switch the default branch to something other than 'master' + script.run('git', 'branch', '-m', 'foobar', cwd=version_pkg_path) + + script.pip( + 'install', '-e', + '%s#egg=version_pkg' % + ('git+file://' + version_pkg_path.abspath.replace('\\', '/')), + ) + version = script.run('version_pkg') + assert '0.1' in version.stdout + + _change_test_package_version(script, version_pkg_path) + script.pip( + 'install', '-e', + '%s#egg=version_pkg' % + ('git+file://' + version_pkg_path.abspath.replace('\\', '/')), + ) + version = script.run('version_pkg') + assert 'some different version' in version.stdout