Skip to content

Commit

Permalink
feat: Improve diagnostic caused by git incorrectly parsing paths on M…
Browse files Browse the repository at this point in the history
…SYS2. (#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>
  • Loading branch information
cr1901 and pre-commit-ci[bot] authored Nov 29, 2024
1 parent 5c6480c commit 23807de
Showing 1 changed file with 19 additions and 4 deletions.
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

0 comments on commit 23807de

Please sign in to comment.