Files
rust/src/etc/pre-push.sh
T
Cheng XU 365d4f4fd0 pre-push.sh: Use python3 if python is not found
Since Python 2 has reached EOL, `python` may not be available in certain
systems (e.g., recent macOS). We should use `python3` in this case to
avoid error like `python: No such file or directory`.
2022-04-11 12:02:40 -07:00

26 lines
582 B
Bash
Executable File

#!/usr/bin/env bash
#
# Call `tidy --bless` before git push
# Copy this script to .git/hooks to activate,
# and remove it from .git/hooks to deactivate.
#
set -Eeuo pipefail
# https://github.com/rust-lang/rust/issues/77620#issuecomment-705144570
unset GIT_DIR
ROOT_DIR="$(git rev-parse --show-toplevel)"
COMMAND="$ROOT_DIR/x.py test tidy --bless"
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
COMMAND="python $COMMAND"
elif ! command -v python &> /dev/null; then
COMMAND="python3 $COMMAND"
fi
echo "Running pre-push script '$COMMAND'"
cd "$ROOT_DIR"
$COMMAND