diff --git a/src/poetry/core/vcs/__init__.py b/src/poetry/core/vcs/__init__.py index 2c2322053..3afa1de31 100644 --- a/src/poetry/core/vcs/__init__.py +++ b/src/poetry/core/vcs/__init__.py @@ -30,6 +30,7 @@ def get_vcs(directory: Path) -> Git | None: [executable(), "rev-parse", "--show-toplevel"], stderr=subprocess.STDOUT, text=True, + encoding="utf-8", ).strip() vcs = Git(Path(git_dir)) diff --git a/tests/vcs/test_vcs.py b/tests/vcs/test_vcs.py index 4fdbc5814..c76c0a7fb 100644 --- a/tests/vcs/test_vcs.py +++ b/tests/vcs/test_vcs.py @@ -15,12 +15,22 @@ from poetry.core.vcs.git import GitUrl from poetry.core.vcs.git import ParsedUrl from poetry.core.vcs.git import _reset_executable +from poetry.core.vcs.git import executable if TYPE_CHECKING: from pytest_mock import MockerFixture +@pytest.fixture +def reset_git() -> None: + _reset_executable() + try: + yield + finally: + _reset_executable() + + @pytest.mark.parametrize( "url, normalized", [ @@ -437,15 +447,12 @@ def test_git_rev_parse_raises_error_on_invalid_repository() -> None: " reasons" ), ) -def test_ensure_absolute_path_to_git(mocker: MockerFixture) -> None: - _reset_executable() - +def test_ensure_absolute_path_to_git(reset_git: None, mocker: MockerFixture) -> None: def checkout_output(cmd: list[str], *args: Any, **kwargs: Any) -> str | bytes: if Path(cmd[0]).name == "where.exe": - return "\n".join([ - str(Path.cwd().joinpath("git.exe")), - "C:\\Git\\cmd\\git.exe", - ]) + return "\n".join( + [str(Path.cwd().joinpath("git.exe")), r"C:\Git\cmd\git.exe"] + ) return b"" @@ -453,20 +460,8 @@ def checkout_output(cmd: list[str], *args: Any, **kwargs: Any) -> str | bytes: Git().run("config") - assert mock.call_args_list[-1][0][0] == [ - "C:\\Git\\cmd\\git.exe", - "config", - ] - + assert mock.call_args_list[-1][0][0] == [r"C:\Git\cmd\git.exe", "config"] -@pytest.mark.skipif( - not WINDOWS, - reason=( - "Retrieving the complete path to git is only necessary on Windows, for security" - " reasons" - ), -) -def test_ensure_existing_git_executable_is_found(mocker: MockerFixture) -> None: mock = mocker.patch.object(subprocess, "check_output", return_value=b"") Git().run("config") @@ -474,14 +469,13 @@ def test_ensure_existing_git_executable_is_found(mocker: MockerFixture) -> None: cmd = Path(mock.call_args_list[-1][0][0][0]) assert cmd.is_absolute() - assert cmd.name == "git.exe" def test_get_vcs_encoding(tmp_path: Path) -> None: repo_path = tmp_path / "répö" repo_path.mkdir() assert repo_path.exists() - assert subprocess.check_call(["git", "init"], cwd=repo_path) == 0 + assert subprocess.check_call([executable(), "init"], cwd=repo_path) == 0 vcs = get_vcs(repo_path) assert vcs is not None assert vcs._work_dir is not None