Skip to content

Commit

Permalink
Use dulwich to fetch global and local git config (#5935)
Browse files Browse the repository at this point in the history
* Use dulwich to fetch git config
* Fix failing test: test_username_password_parameter_is_not_passed_to_dulwich
* Fix failing test: test_configured_repository_http_auth
* Require dulwich ^0.20.44
  • Loading branch information
fredrikaverpil authored Jul 13, 2022
1 parent bd9c5c8 commit 879a144
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
44 changes: 22 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ tomlkit = ">=0.7.0,<1.0.0"
virtualenv = "(>=20.4.3,<20.4.5 || >=20.4.7)"
xattr = { version = "^0.9.7", markers = "sys_platform == 'darwin'" }
urllib3 = "^1.26.0"
dulwich = "^0.20.35"
dulwich = "^0.20.44"

[tool.poetry.dev-dependencies]
tox = "^3.18"
Expand Down
5 changes: 3 additions & 2 deletions src/poetry/vcs/git/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def _fetch_remote_refs(cls, url: str, local: Repo) -> FetchPackResult:
kwargs["username"] = credentials.username
kwargs["password"] = credentials.password

client, path = get_transport_and_path(url, **kwargs)
config = local.get_config_stack()
client, path = get_transport_and_path(url, config=config, **kwargs)

with local:
result: FetchPackResult = client.fetch(
Expand Down Expand Up @@ -329,7 +330,7 @@ def _clone_submodules(cls, repo: Repo) -> None:
modules_config = repo_root.joinpath(".gitmodules")

if modules_config.exists():
config = ConfigFile.from_path(modules_config)
config = ConfigFile.from_path(str(modules_config))

url: bytes
path: bytes
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/test_utils_vcs_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from dulwich.client import HTTPUnauthorized
from dulwich.client import get_transport_and_path
from dulwich.config import ConfigFile
from dulwich.repo import Repo
from poetry.core.pyproject.toml import PyProjectTOML

Expand Down Expand Up @@ -280,6 +281,12 @@ def test_configured_repository_http_auth(
}
)

dummy_git_config = ConfigFile()
mocker.patch(
"poetry.vcs.git.backend.Repo.get_config_stack",
return_value=dummy_git_config,
)

mocker.patch(
"poetry.vcs.git.backend.get_default_authenticator",
return_value=Authenticator(config=config),
Expand All @@ -292,6 +299,7 @@ def test_configured_repository_http_auth(

spy_get_transport_and_path.assert_called_with(
location=source_url,
config=dummy_git_config,
username=GIT_USERNAME,
password=GIT_PASSWORD,
)
Expand All @@ -306,13 +314,20 @@ def test_username_password_parameter_is_not_passed_to_dulwich(
spy_clone = mocker.spy(Git, "_clone")
spy_get_transport_and_path = mocker.spy(backend, "get_transport_and_path")

dummy_git_config = ConfigFile()
mocker.patch(
"poetry.vcs.git.backend.Repo.get_config_stack",
return_value=dummy_git_config,
)

with Git.clone(url=source_url, branch="0.1") as repo:
assert_version(repo, BRANCH_TO_REVISION_MAP["0.1"])

spy_clone.assert_called_once()

spy_get_transport_and_path.assert_called_with(
location=source_url,
config=dummy_git_config,
)
spy_get_transport_and_path.assert_called_once()

Expand Down

0 comments on commit 879a144

Please sign in to comment.