From 7c38bf326047dc5c13e7e7df7807919eada22da2 Mon Sep 17 00:00:00 2001 From: alexprabhat99 Date: Thu, 14 Nov 2024 14:48:17 +0530 Subject: [PATCH 1/6] expose git errors when run as a subprocess --- src/poetry/vcs/git/backend.py | 5 ++--- src/poetry/vcs/git/system.py | 7 ++++--- tests/integration/test_utils_vcs_git.py | 8 ++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/poetry/vcs/git/backend.py b/src/poetry/vcs/git/backend.py index eddd0efd75e..914237209fd 100644 --- a/src/poetry/vcs/git/backend.py +++ b/src/poetry/vcs/git/backend.py @@ -231,10 +231,9 @@ def _clone_legacy(url: str, refspec: GitRefSpec, target: Path) -> Repo: try: SystemGit.clone(url, target) - except CalledProcessError: + except CalledProcessError as e: raise PoetryConsoleError( - f"Failed to clone {url}, check your git configuration and permissions" - " for this repository." + f"Failed to clone {url}\n {e.stderr}" ) if revision: diff --git a/src/poetry/vcs/git/system.py b/src/poetry/vcs/git/system.py index 27ab0330002..7f2bcaadc83 100644 --- a/src/poetry/vcs/git/system.py +++ b/src/poetry/vcs/git/system.py @@ -40,10 +40,11 @@ def run(*args: Any, **kwargs: Any) -> None: git_command = find_git_command() env = os.environ.copy() env["GIT_TERMINAL_PROMPT"] = "0" - subprocess.check_call( # type: ignore[call-arg] + subprocess.run( git_command + list(args), - stderr=subprocess.DEVNULL, - stdout=subprocess.DEVNULL, + check=True, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, env=env, text=True, encoding="utf-8", diff --git a/tests/integration/test_utils_vcs_git.py b/tests/integration/test_utils_vcs_git.py index 1e4229e0f48..8087612300b 100644 --- a/tests/integration/test_utils_vcs_git.py +++ b/tests/integration/test_utils_vcs_git.py @@ -435,3 +435,11 @@ def test_relative_submodules_with_ssh( "ssh://github.com/python-poetry/test-fixture-vcs-repository.git", "ssh://github.com/python-poetry/test-fixture-vcs-repository.git", ] + +def test_git_error_is_exposed_for_non_existent_branch(source_url: str) -> None: + branch = uuid.uuid4().hex + + with pytest.raises(PoetryConsoleError) as e: + Git.clone(url=source_url, branch=branch) + + assert f"Failed to clone {source_url} at '{branch}', verify ref exists on remote." in str(e.value) \ No newline at end of file From 3460e8a9bd6d964bb582bfbd272ad7e783045bce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:36:36 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/poetry/vcs/git/backend.py | 4 +--- tests/integration/test_utils_vcs_git.py | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/poetry/vcs/git/backend.py b/src/poetry/vcs/git/backend.py index 914237209fd..da0b58db68f 100644 --- a/src/poetry/vcs/git/backend.py +++ b/src/poetry/vcs/git/backend.py @@ -232,9 +232,7 @@ def _clone_legacy(url: str, refspec: GitRefSpec, target: Path) -> Repo: try: SystemGit.clone(url, target) except CalledProcessError as e: - raise PoetryConsoleError( - f"Failed to clone {url}\n {e.stderr}" - ) + raise PoetryConsoleError(f"Failed to clone {url}\n {e.stderr}") if revision: revision.replace("refs/head/", "") diff --git a/tests/integration/test_utils_vcs_git.py b/tests/integration/test_utils_vcs_git.py index 8087612300b..52076b08096 100644 --- a/tests/integration/test_utils_vcs_git.py +++ b/tests/integration/test_utils_vcs_git.py @@ -436,10 +436,14 @@ def test_relative_submodules_with_ssh( "ssh://github.com/python-poetry/test-fixture-vcs-repository.git", ] + def test_git_error_is_exposed_for_non_existent_branch(source_url: str) -> None: branch = uuid.uuid4().hex with pytest.raises(PoetryConsoleError) as e: Git.clone(url=source_url, branch=branch) - assert f"Failed to clone {source_url} at '{branch}', verify ref exists on remote." in str(e.value) \ No newline at end of file + assert ( + f"Failed to clone {source_url} at '{branch}', verify ref exists on remote." + in str(e.value) + ) From b68e1777a650e0be968785c88035930ee587f55a Mon Sep 17 00:00:00 2001 From: alexprabhat99 Date: Thu, 14 Nov 2024 15:16:22 +0530 Subject: [PATCH 3/6] capture_output for git subprocess --- src/poetry/vcs/git/system.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/poetry/vcs/git/system.py b/src/poetry/vcs/git/system.py index 7f2bcaadc83..763bc810a59 100644 --- a/src/poetry/vcs/git/system.py +++ b/src/poetry/vcs/git/system.py @@ -43,8 +43,7 @@ def run(*args: Any, **kwargs: Any) -> None: subprocess.run( git_command + list(args), check=True, - stderr=subprocess.PIPE, - stdout=subprocess.PIPE, + capture_output=True env=env, text=True, encoding="utf-8", From 3c76d5c09503bf74861f2c7e03d6aeb7a7f0d246 Mon Sep 17 00:00:00 2001 From: alexprabhat99 Date: Thu, 14 Nov 2024 15:17:50 +0530 Subject: [PATCH 4/6] added missing comma --- src/poetry/vcs/git/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/poetry/vcs/git/system.py b/src/poetry/vcs/git/system.py index 763bc810a59..f994d677faf 100644 --- a/src/poetry/vcs/git/system.py +++ b/src/poetry/vcs/git/system.py @@ -43,7 +43,7 @@ def run(*args: Any, **kwargs: Any) -> None: subprocess.run( git_command + list(args), check=True, - capture_output=True + capture_output=True, env=env, text=True, encoding="utf-8", From 627cab017a9532ee38d01286d1cf0a1c6b027120 Mon Sep 17 00:00:00 2001 From: Alex Prabhat Bara <50404684+alexprabhat99@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:24:22 +0530 Subject: [PATCH 5/6] updated test for #9819 fix --- tests/integration/test_utils_vcs_git.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_utils_vcs_git.py b/tests/integration/test_utils_vcs_git.py index 52076b08096..9f230088b38 100644 --- a/tests/integration/test_utils_vcs_git.py +++ b/tests/integration/test_utils_vcs_git.py @@ -437,13 +437,14 @@ def test_relative_submodules_with_ssh( ] -def test_git_error_is_exposed_for_non_existent_branch(source_url: str) -> None: +def test_git_error_is_exposed_for_non_existent_repo() -> None: + source_url = "https://github.com/python-poetry/test-fixture-vcs-repo.git" branch = uuid.uuid4().hex with pytest.raises(PoetryConsoleError) as e: Git.clone(url=source_url, branch=branch) assert ( - f"Failed to clone {source_url} at '{branch}', verify ref exists on remote." + f"remote: Repository not found." in str(e.value) ) From 098b40cd093f4df6778141dc2d23449cbc728817 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:56:07 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/integration/test_utils_vcs_git.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/integration/test_utils_vcs_git.py b/tests/integration/test_utils_vcs_git.py index 9f230088b38..15cd5922b0f 100644 --- a/tests/integration/test_utils_vcs_git.py +++ b/tests/integration/test_utils_vcs_git.py @@ -444,7 +444,4 @@ def test_git_error_is_exposed_for_non_existent_repo() -> None: with pytest.raises(PoetryConsoleError) as e: Git.clone(url=source_url, branch=branch) - assert ( - f"remote: Repository not found." - in str(e.value) - ) + assert "remote: Repository not found." in str(e.value)