#!/bin/bash GREEN="\e[1;32m" RED="\e[31m" CYAN="\e[36m" ENDCOLOR="\e[0m" read -p "Would you like to run tests & clippy before you push remotely ? (y/n): " choice if [ "$choice" != "y" ]; then echo -e "${CYAN}pre-push hook will not be installed ${ENDCOLOR}" exit 0 else cat <> .git/hooks/pre-push #!/bin/bash set -e echo "Running tests.." cargo test if [ \$? -ne 0 ]; then echo -e "${RED}hook failed, push aborted! ${ENDCOLOR}" exit 1 fi echo "Running Clippy.." cargo clippy -- -D warnings -A incomplete_features -W clippy::dbg_macro -W clippy::print_stdout if [ \$? -ne 0 ]; then echo -e "${RED}pre-push checks failed! ${ENDCOLOR}" exit 1 else echo -e "${GREEN}pre-push checks went successful!${ENDCOLOR}" fi exit 0 EOF chmod +x .git/hooks/pre-push printf "${GREEN}pre-push hook installed!${ENDCOLOR}" fi