Skip to content

pip freeze figures out the current commit SHA for a git repo but not (reliably) the current branch #2059

Closed
@bjonen

Description

@bjonen

The problem originates from this line.

names_by_commit = dict((commit, ref) for ref, commit in refs.items())

When local branches track up to date remote branches, the mapping from SHA to branch is not unique and remote branches with syntax "origin/my_branch" may be picked (see comment in the code), even though they are NOT checked out.
Finally, pkg_resources does not allow a slash in the version pattern and raises a ValueError if a branch name containing a slash is picked.

My use case:
I have a local git repo which originates from a different local path on my file system. I installed it via:

pip install -e c:/workspace/my_proj

Now I do

pip freeze > requirements.txt

The file looks something like this:

-e git+<path_to_origin>/my_proj.git@<SHA>#egg=my_proj-origin/<branch>

If I then create a new virtual environment and try to install my requirements file I get an error in pip_vendor\pkg_resources.py", line 2573, in scan_list.

ValueError: ('Expected version spec in', 'my_proj-origin/<branch>', 'at', '/<branch>')

I noticed that the problem goes away when the line in the requirements file reads:

-e git+<path_to_origin>/my_proj.git@<SHA>#egg=my_proj-<branch>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: vcspip's interaction with version control systems like git, svn and bzrauto-lockedOutdated issues that have been locked by automationresolution: deferred till PRFurther discussion will happen when a PR is madetype: bugA confirmed bug or unintended behavior

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions