Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve diagnostic caused by git incorrectly parsing paths on MSYS2. #267

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 19 additions & 4 deletions src/pdm/backend/hooks/version/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,25 @@ def _subprocess_call(
env.update(extra_env)
if isinstance(cmd, str):
cmd = shlex.split(cmd)
proc = subprocess.Popen(
cmd, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
out, err = proc.communicate()
try:
proc = subprocess.Popen(
cmd, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
out, err = proc.communicate()
except NotADirectoryError as e:
if hasattr(e, "winerror") and e.winerror == 267:
# https://github.com/pdm-project/pdm-backend/issues/197
# More helpful diagnostic.
import textwrap

err_msg = f"""\
The above error is most likely caused by an unsupported
MSYS2 git binary at {cmd[0]}. Please point your PATH to
a different git binary such as Git For Windows.
"""
raise subprocess.SubprocessError(textwrap.dedent(err_msg)) from e
else:
raise e
return (
proc.returncode,
out.decode("utf-8", "surrogateescape").strip(),
Expand Down