hooks/pre-commit
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RC='\033[0m' # Reset Color
PREFIX="${GREEN}[PRECOMMIT]${RC}"
FAILURE="${RED}FAILED${RC}"
WARNING="${RED}[WARNING]${RC}"
SKIPPED="${YELLOW}SKIPPED${RC}"
SUCCESS="${GREEN}ok${RC}"
# cd to the rust directory
cd rust_ipv8
if [[ $? -ne 0 ]]; then
printf "${FAILURE} rust_ipv8 directory not found\n"
exit 1
fi
# Check if rustfmt is installed
printf "${PREFIX} Checking for rustfmt ... "
OUT=$(cargo +stable fmt --version 2>&1 > /dev/null ) # Save the output of the command to OUT for later printing
if [[ $? -eq 0 ]]; then
printf "${SUCCESS}\n"
else
printf "${FAILURE}\n"
printf "${OUT}\n"
exit 1
fi
# Check rustfmt against the git tree
printf "${PREFIX} Checking formatting ... "
command cargo +stable fmt -- --check > /dev/null
if [[ $? == 0 ]]; then
printf "${SUCCESS}\n"
exit 0
fi
# move out again so other hooks could be ran
cd ..
# If things went wrong
printf "${FAILURE}\n"
exit 1