diff --git a/news/4448.bugfix b/news/4448.bugfix new file mode 100644 index 000000000..28088dd63 --- /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 6262f2729..b7b128177 100644 --- a/src/pip/_internal/vcs/git.py +++ b/src/pip/_internal/vcs/git.py @@ -132,7 +132,7 @@ class Git(VersionControl): 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 d8175331e..4845f91ad 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