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.
This commit is contained in:
Tad Hardesty
2020-06-03 10:17:38 -07:00
committed by GitHub
parent 1ff5e8202b
commit 17348c3f99
3 changed files with 12 additions and 6 deletions
+9 -4
View File
@@ -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 "$@"