Skip to content

Conversation

@matteius
Copy link
Member

Summary

Fixes #6076

Problem

When installing a git dependency over SSH without specifying a branch/ref (e.g., git+ssh://git@github.com/user/repo.git#egg=package), the URL was being incorrectly parsed. The @ symbol in git@github.com was being treated as a branch/ref separator, resulting in corrupted Pipfile.lock entries like:

"git": "git+ssh://git"

instead of the correct:

"git": "git+ssh://git@github.com/user/repo.git"

This caused pip to fail with errors like:

fatal: 'github.com/user/repo.git' does not appear to be a git repository

Root Cause

In pipenv/project.py, the generate_package_pipfile_entry() function was using rsplit("@", 1) to extract the branch/ref from VCS URLs. This incorrectly split on the @ in SSH URLs like git@github.com, treating github.com/user/repo.git as the ref and git+ssh://git as the URL.

Solution

The fix checks if the @ symbol is in the path part of the URL (indicating a branch/ref) rather than in the netloc (hostname) part before splitting. This matches the behavior of the existing normalize_vcs_url() function in pipenv/utils/dependencies.py.

Changes

  1. pipenv/project.py: Updated generate_package_pipfile_entry() to use urllib.parse.urlparse() to check if @ is in the path before treating it as a ref separator.

  2. tests/unit/test_vcs.py: Added regression tests for SSH URL handling with and without branch refs.

Testing

  • All existing VCS tests pass (27 tests)
  • Added 5 new parametrized test cases specifically for SSH URL handling

Pull Request opened by Augment Code with guidance from the PR author

When installing a git dependency over SSH without specifying a branch/ref
(e.g., git+ssh://git@github.com/user/repo.git#egg=package), the URL was
being incorrectly parsed. The @ symbol in 'git@github.com' was being
treated as a branch/ref separator, resulting in corrupted entries like:

    "git": "git+ssh://git"

instead of the correct:

    "git": "git+ssh://git@github.com/user/repo.git"

The fix checks if the @ symbol is in the path part of the URL (indicating
a branch/ref) rather than in the netloc (hostname) part before splitting.
This matches the behavior of the normalize_vcs_url() function.

Added regression tests for SSH URL handling with and without branch refs.

Fixes #6076
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Installing git dependencies over ssh often leads to corrupted pipfile.lock or pipfile dependencies

2 participants