difftreelog
feature: check formating before push
in: master
3 files changed
.githooks/pre-commitdiffbeforeafterboth--- /dev/null
+++ b/.githooks/pre-commit
@@ -0,0 +1,42 @@
+#!/bin/bash
+#
+# Pre-push hook verifying that inappropriate code will not be pushed.
+
+# Colors for the terminal output
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+NC='\033[0m' # No Color
+
+echo "Starting cargo fmt.."
+cargo fmt --check
+FMT_EXIT="$?"
+
+# Check that prettier formatting rules are not violated.
+if [[ "${FMT_EXIT}" = 0 ]]; then
+ echo -e "${GREEN}cargo fmt succeded${NC}"
+else
+ echo -e "${RED}Commit error!${NC}"
+ echo "Please format the code via 'cargo fmt', cannot commit unformatted code"
+ exit 1
+fi
+
+STAGED_TEST_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".ts$\|.js$")
+
+if [[ "$STAGED_TEST_FILES" = "" ]]; then
+ echo -e "${GREEN}eslint succeded${NC}"
+ exit 0
+fi
+
+echo "Starting eslint.."
+./tests/node_modules/.bin/eslint --max-warnings 0 ${STAGED_TEST_FILES[@]}
+ESLINT_EXIT="$?"
+
+if [[ "${ESLINT_EXIT}" = 0 ]]; then
+ echo -e "${GREEN}eslint succeded${NC}"
+else
+ echo -e "${RED}Commit error!${NC}"
+ echo "Please format the code via 'yarn fix', cannot Commit unformatted code"
+ exit 1
+fi
+
+exit $?
\ No newline at end of file
.githooks/pre-pushdiffbeforeafterboth1#!/bin/bash2#3# Pre-push hook verifying that inappropriate code will not be pushed.45# Colors for the terminal output6RED='\033[0;31m'7NC='\033[0m' # No Color89# Check that prettier formatting rules are not violated.10if ! cargo fmt --check; then11 echo -e "${RED}Push error!${NC}"12 echo "Please format the code via 'cargo fmt', cannot push unformatted code"13 exit 114fi1516STAGED_TEST_FILES=$(git diff --cached --name-only --diff-filter=ACM @{upstream}| grep ".ts$\|.js$")1718DIFF_EXIT="$?"1920if [[ "${DIFF_EXIT}" != 0 ]]; then21 echo -e "${GREEN}eslint succeded${NC}"22 exit 023fi2425if [[ "$STAGED_TEST_FILES" = "" ]]; then26 echo -e "${GREEN}eslint succeded${NC}"27 exit 028fi2930echo "Starting eslint.."31./tests/node_modules/.bin/eslint --max-warnings 0 ${STAGED_TEST_FILES[@]}32ESLINT_EXIT="$?"3334if [[ "${ESLINT_EXIT}" = 0 ]]; then35 echo -e "${GREEN}eslint succeded${NC}"36else37 echo -e "${RED}Commit error!${NC}"38 echo "Please format the code via 'yarn fix', cannot Commit unformatted code"39 exit 140fi4142exit $?init.shdiffbeforeafterboth--- /dev/null
+++ b/init.sh
@@ -0,0 +1 @@
+git config --local core.hooksPath ./.githooks
\ No newline at end of file