Files
neon/pre-commit.sh.tpl
Dmitry Rodionov 35b60d509f Add support for code format checking using rustfmt in optional
pre-commit hook and in ci pipeline. Found issues can be fixed
automatically via make fmt.
2021-08-23 17:28:45 +03:00

35 lines
740 B
Smarty
Executable File

#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
function check {
name=$1
prefix=$2
files=$(git diff --cached --name-only --diff-filter=ACM | grep $prefix)
shift; shift;
echo -n "checking $name ";
if [ -z "$files" ]; then
echo -e "${CYAN}[NOT APPLICABLE]${NC}"
exit 0;
fi
cd $(git rev-parse --show-toplevel)
out=$($@ $files)
if [ $? -eq 0 ];
then
echo -e "${GREEN}[OK]${NC}"
cd -
else
echo -e "${RED}[FAILED]${NC}"
echo -e "Please inspect the output below and run make fmt to fix automatically\n"
echo -e "$out"
exit 1
fi
}
check rustfmt .rs rustfmt --check --edition=2018