Skip to content

Commit 7b8ba87

Browse files
authored
Preserve uncleaned VCS URL in the lock file. (#6257)
* Preserve uncleaned vcs URL in the lock file. * add news fragment * add new tests
1 parent 6e562cb commit 7b8ba87

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

news/6256.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes regression in lock file generation that caused environment variable references (e.g., ${GIT_PASSWORD}) in VCS URLs to be stripped out. This restores the ability to use credential placeholders in version control system URLs.

pipenv/utils/dependencies.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,7 @@ def clean_resolved_dep(project, dep, is_top_level=False, current_entry=None):
283283
[extra.strip() for extra in extras_section.split(",")]
284284
)
285285

286-
# Extract the clean VCS URL
287-
clean_vcs_url = extract_vcs_url(vcs_url)
288-
289-
lockfile[vcs_type] = clean_vcs_url
286+
lockfile[vcs_type] = vcs_url
290287
lockfile["ref"] = dep.get("ref")
291288
if "subdirectory" in dep:
292289
lockfile["subdirectory"] = dep["subdirectory"]

tests/integration/test_install_vcs.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import pytest
24

35

@@ -8,3 +10,35 @@ def test_install_github_vcs(pipenv_instance_pypi):
810
c = p.pipenv("install git+https://github.com/reagento/adaptix.git@2.16")
911
assert not c.returncode
1012
assert "dataclass-factory" in p.pipfile["packages"]
13+
14+
15+
@pytest.mark.basic
16+
@pytest.mark.install
17+
@pytest.mark.parametrize("use_credentials", [True, False])
18+
def test_install_github_vcs_with_credentials(pipenv_instance_pypi, use_credentials):
19+
with pipenv_instance_pypi() as p:
20+
# Set environment variables
21+
os.environ['GIT_REPO'] = 'github.com/reagento/adaptix.git'
22+
if use_credentials:
23+
os.environ['GIT_USERNAME'] = 'git' # Use 'git' as a dummy username
24+
os.environ['GIT_PASSWORD'] = '' # Empty password for public repos
25+
url = "git+https://${GIT_USERNAME}:${GIT_PASSWORD}@${GIT_REPO}@2.16"
26+
else:
27+
url = "git+https://${GIT_REPO}@2.16"
28+
29+
# Use single quotes to prevent shell expansion
30+
c = p.pipenv(f"install '{url}'")
31+
assert c.returncode == 0, f"Install failed with error: {c.stderr}"
32+
33+
assert "dataclass-factory" in p.pipfile["packages"]
34+
35+
# Check if the URL in the lockfile still contains the environment variables
36+
lockfile_content = p.lockfile
37+
assert "${GIT_REPO}" in lockfile_content['default']['dataclass-factory']['git']
38+
if use_credentials:
39+
assert "${GIT_USERNAME}" in lockfile_content['default']['dataclass-factory']['git']
40+
assert "${GIT_PASSWORD}" in lockfile_content['default']['dataclass-factory']['git']
41+
42+
# Verify that the package is installed and usable
43+
c = p.pipenv("run python -c 'import dataclass_factory'")
44+
assert c.returncode == 0, f"Failed to import library: {c.stderr}"

tests/unit/test_dependencies.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
from pipenv.utils.dependencies import clean_resolved_dep
3+
4+
def test_clean_resolved_dep_with_vcs_url():
5+
project = {} # Mock project object, adjust as needed
6+
dep = {
7+
"name": "example-package",
8+
"git": "git+https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/username/repo.git",
9+
"ref": "main"
10+
}
11+
12+
result = clean_resolved_dep(project, dep)
13+
14+
assert "example-package" in result
15+
assert result["example-package"]["git"] == "git+https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/username/repo.git"
16+
assert result["example-package"]["ref"] == "main"
17+
18+
def test_clean_resolved_dep_with_vcs_url_and_extras():
19+
project = {} # Mock project object, adjust as needed
20+
dep = {
21+
"name": "example-package",
22+
"git": "git+https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/username/repo.git[extra1,extra2]",
23+
"ref": "main"
24+
}
25+
26+
result = clean_resolved_dep(project, dep)
27+
28+
assert "example-package" in result
29+
assert result["example-package"]["git"] == "git+https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/username/repo.git[extra1,extra2]"
30+
assert result["example-package"]["ref"] == "main"
31+
assert result["example-package"]["extras"] == ["extra1", "extra2"]

0 commit comments

Comments
 (0)