Skip to content

Commit 23807de

Browse files
feat: Improve diagnostic caused by git incorrectly parsing paths on MSYS2. (#267)
* Improve diagnostic caused by git incorrectly parsing paths on MSYS2. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5c6480c commit 23807de

File tree

1 file changed

+19
-4
lines changed
  • src/pdm/backend/hooks/version

1 file changed

+19
-4
lines changed

src/pdm/backend/hooks/version/scm.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,25 @@ def _subprocess_call(
5151
env.update(extra_env)
5252
if isinstance(cmd, str):
5353
cmd = shlex.split(cmd)
54-
proc = subprocess.Popen(
55-
cmd, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE
56-
)
57-
out, err = proc.communicate()
54+
try:
55+
proc = subprocess.Popen(
56+
cmd, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE
57+
)
58+
out, err = proc.communicate()
59+
except NotADirectoryError as e:
60+
if hasattr(e, "winerror") and e.winerror == 267:
61+
# https://github.com/pdm-project/pdm-backend/issues/197
62+
# More helpful diagnostic.
63+
import textwrap
64+
65+
err_msg = f"""\
66+
The above error is most likely caused by an unsupported
67+
MSYS2 git binary at {cmd[0]}. Please point your PATH to
68+
a different git binary such as Git For Windows.
69+
"""
70+
raise subprocess.SubprocessError(textwrap.dedent(err_msg)) from e
71+
else:
72+
raise e
5873
return (
5974
proc.returncode,
6075
out.decode("utf-8", "surrogateescape").strip(),

0 commit comments

Comments
 (0)