From 273fb90106726daa16e1033eca0d677de76345eb Mon Sep 17 00:00:00 2001 From: Nils Hjelte Date: Sat, 9 Nov 2024 22:57:12 +0100 Subject: [PATCH] More robust check of bash version (#2639) --- CHANGES.rst | 3 ++- src/click/shell_completion.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8ce12a8ce..df4e5c79a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,7 +16,8 @@ Unreleased :issue:`2632` - Fix ``click.echo(color=...)`` passing ``color`` to coloroma so it can be forced on Windows. :issue:`2606`. - +- More robust bash version check, fixing problem on Windows with git-bash. + :issue:`2638` Version 8.1.7 ------------- diff --git a/src/click/shell_completion.py b/src/click/shell_completion.py index dc9e00b9b..07d0f09ba 100644 --- a/src/click/shell_completion.py +++ b/src/click/shell_completion.py @@ -303,12 +303,19 @@ class BashComplete(ShellComplete): @staticmethod def _check_version() -> None: + import shutil import subprocess - output = subprocess.run( - ["bash", "-c", 'echo "${BASH_VERSION}"'], stdout=subprocess.PIPE - ) - match = re.search(r"^(\d+)\.(\d+)\.\d+", output.stdout.decode()) + bash_exe = shutil.which("bash") + + if bash_exe is None: + match = None + else: + output = subprocess.run( + [bash_exe, "--norc", "-c", 'echo "${BASH_VERSION}"'], + stdout=subprocess.PIPE, + ) + match = re.search(r"^(\d+)\.(\d+)\.\d+", output.stdout.decode()) if match is not None: major, minor = match.groups()