From 17348c3f9929debf96b3c852bf3de3007f6b7cf0 Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Wed, 3 Jun 2020 10:17:38 -0700 Subject: [PATCH] Update precommit hooks to work in GitHub Desktop (#51404) Turns out GitHub Desktop actually does bundle a sh.exe, just not a bash. Also tries to look for the py launcher to help people who didn't check the "Add Python to PATH" option. --- tools/hooks/dmi.merge | 2 +- tools/hooks/pre-commit.hook | 3 ++- tools/hooks/python.sh | 13 +++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/hooks/dmi.merge b/tools/hooks/dmi.merge index 4e2717867e8..7fd9f171bf0 100755 --- a/tools/hooks/dmi.merge +++ b/tools/hooks/dmi.merge @@ -1,2 +1,2 @@ -#!/bin/bash +#!/bin/sh exec tools/hooks/python.sh -m merge_driver_dmi "$@" diff --git a/tools/hooks/pre-commit.hook b/tools/hooks/pre-commit.hook index 7eccda6f58d..970be47a44b 100755 --- a/tools/hooks/pre-commit.hook +++ b/tools/hooks/pre-commit.hook @@ -1,2 +1,3 @@ -#!/bin/bash +#!/bin/sh +# `sh` must be used here instead of `bash` to support GitHub Desktop. exec tools/hooks/python.sh -m precommit diff --git a/tools/hooks/python.sh b/tools/hooks/python.sh index 32557070f48..f575ebdac42 100755 --- a/tools/hooks/python.sh +++ b/tools/hooks/python.sh @@ -1,17 +1,22 @@ -#!/bin/bash +#!/bin/sh +# `sh` must be used here instead of `bash` to support GitHub Desktop. set -e if command -v python3 >/dev/null 2>&1; then PY=python3 -else +elif command -v python >/dev/null 2>&1; then PY=python +elif command -v py >/dev/null 2>&1; then + PY=py +else + echo "Please install Python 3.6 or later." fi PATHSEP=$($PY - <<'EOF' import sys, os if sys.version_info.major != 3 or sys.version_info.minor < 6: - sys.stderr.write("Python 3.6+ is required: " + sys.version + "\n") + sys.stderr.write("Python 3.6 or later is required, but you have:\n" + sys.version + "\n") exit(1) print(os.pathsep) EOF ) export PYTHONPATH=tools/mapmerge2/${PATHSEP}${PYTHONPATH} -$PY "$@" +exec $PY "$@"