2017-04-13 10:26:48 +03:00
|
|
|
#!/bin/bash
|
|
|
|
# Modified from https://github.com/chaitanyagupta/gitutils
|
|
|
|
|
2022-08-08 14:28:31 +03:00
|
|
|
[ -n "$CI" ] && exit 0
|
|
|
|
|
2022-10-27 07:47:10 +03:00
|
|
|
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
|
|
if [ "$GIT_BRANCH" = "main" ]; then
|
|
|
|
yarn lint-staged --relative
|
|
|
|
lintStatus=$?
|
2022-08-08 14:28:31 +03:00
|
|
|
|
2022-10-27 07:47:10 +03:00
|
|
|
if [ $lintStatus -ne 0 ]; then
|
|
|
|
echo "❌ Linting failed"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-08-08 14:28:31 +03:00
|
|
|
fi
|
|
|
|
|
2017-04-13 10:26:48 +03:00
|
|
|
green='\033[0;32m'
|
|
|
|
no_color='\033[0m'
|
|
|
|
grey='\033[0;90m'
|
2023-03-28 13:13:16 +03:00
|
|
|
red='\033[0;31m'
|
2017-04-13 10:26:48 +03:00
|
|
|
|
|
|
|
ROOT_DIR=$(git rev-parse --show-cdup)
|
|
|
|
SUBMODULES=$(grep path ${ROOT_DIR}.gitmodules | sed 's/^.*path = //')
|
2023-03-28 13:13:16 +03:00
|
|
|
MOD_SUBMODULES=$(git diff --cached --name-only --ignore-submodules=none | grep -F "$SUBMODULES")
|
2017-04-13 10:26:48 +03:00
|
|
|
|
|
|
|
echo -e "Checking submodules ${grey}(pre-commit hook)${no_color} "
|
|
|
|
|
|
|
|
# If no modified submodules, exit with status code 0, else prompt the
|
|
|
|
# user and exit accordingly
|
|
|
|
if [[ -n "$MOD_SUBMODULES" ]]; then
|
|
|
|
echo "Submodules to be committed:"
|
|
|
|
echo " (use \"git reset HEAD <file>...\" to unstage)"
|
|
|
|
echo
|
|
|
|
|
|
|
|
for SUB in $MOD_SUBMODULES
|
|
|
|
do
|
|
|
|
echo -e "\t${green}modified:\t$SUB${no_color}"
|
|
|
|
done
|
|
|
|
echo
|
2023-03-28 13:13:16 +03:00
|
|
|
echo -e "${red}Aborting commit due to submodule update. Please unstage the submodule(s) and commit again.${no_color}"
|
|
|
|
exit 1
|
2017-04-13 10:26:48 +03:00
|
|
|
else
|
|
|
|
echo "No submodules in commit, continuing..."
|
|
|
|
exit 0
|
|
|
|
fi
|