From 23807de811b13d7b392f48112e7ad13690dbcece Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Thu, 28 Nov 2024 21:10:04 -0500 Subject: [PATCH] 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> --- src/pdm/backend/hooks/version/scm.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/pdm/backend/hooks/version/scm.py b/src/pdm/backend/hooks/version/scm.py index f6da7a7..481313b 100644 --- a/src/pdm/backend/hooks/version/scm.py +++ b/src/pdm/backend/hooks/version/scm.py @@ -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(),