Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/poetry/vcs/git/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,8 @@ def _clone_legacy(url: str, refspec: GitRefSpec, target: Path) -> Repo:

try:
SystemGit.clone(url, target)
except CalledProcessError:
raise PoetryConsoleError(
f"Failed to clone {url}, check your git configuration and permissions"
" for this repository."
)
except CalledProcessError as e:
raise PoetryConsoleError(f"Failed to clone {url}\n {e.stderr}")
Copy link
Member

@abn abn Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest the git error be surfaced via logger.debug instead. The proposed change is too noisy.

Suggested change
raise PoetryConsoleError(f"Failed to clone {url}\n {e.stderr}")
logger.debug("Git command returned the following error:\n%s", e.stderr)
raise PoetryConsoleError(
f"Failed to clone {url}, check your git configuration and permissions"
" for this repository."
)


if revision:
revision.replace("refs/head/", "")
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/vcs/git/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ 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,
capture_output=True,
env=env,
text=True,
encoding="utf-8",
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/test_utils_vcs_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,13 @@ 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_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 "remote: Repository not found." in str(e.value)