2017-04-13 08:26:48 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# Modified from https://github.com/chaitanyagupta/gitutils
|
|
|
|
|
2022-08-08 13:28:31 +02:00
|
|
|
[ -n "$CI" ] && exit 0
|
|
|
|
|
2022-10-27 11:47:10 +07:00
|
|
|
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
|
|
if [ "$GIT_BRANCH" = "main" ]; then
|
|
|
|
yarn lint-staged --relative
|
|
|
|
lintStatus=$?
|
2022-08-08 13:28:31 +02:00
|
|
|
|
2022-10-27 11:47:10 +07:00
|
|
|
if [ $lintStatus -ne 0 ]; then
|
|
|
|
echo "❌ Linting failed"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-08-08 13:28:31 +02:00
|
|
|
fi
|
|
|
|
|
2017-04-13 08:26:48 +01:00
|
|
|
green='\033[0;32m'
|
|
|
|
no_color='\033[0m'
|
|
|
|
grey='\033[0;90m'
|
2023-03-28 12:13:16 +02:00
|
|
|
red='\033[0;31m'
|
2017-04-13 08:26:48 +01:00
|
|
|
|
|
|
|
ROOT_DIR=$(git rev-parse --show-cdup)
|
|
|
|
SUBMODULES=$(grep path ${ROOT_DIR}.gitmodules | sed 's/^.*path = //')
|
2023-03-28 12:13:16 +02:00
|
|
|
MOD_SUBMODULES=$(git diff --cached --name-only --ignore-submodules=none | grep -F "$SUBMODULES")
|
2017-04-13 08:26:48 +01:00
|
|
|
|
|
|
|
echo -e "Checking submodules ${grey}(pre-commit hook)${no_color} "
|
|
|
|
|
2024-10-12 11:40:31 +01:00
|
|
|
# If no modified submodules, exit with status code 0, else remove them and continue
|
2017-04-13 08:26:48 +01:00
|
|
|
if [[ -n "$MOD_SUBMODULES" ]]; then
|
2024-10-12 11:40:31 +01:00
|
|
|
echo -e "${grey}Removing submodules from commit...${no_color}"
|
2017-04-13 08:26:48 +01:00
|
|
|
for SUB in $MOD_SUBMODULES
|
|
|
|
do
|
2024-10-12 11:40:31 +01:00
|
|
|
git reset --quiet HEAD "$SUB"
|
|
|
|
echo -e "\t${grey}removed:\t$SUB${no_color}"
|
2017-04-13 08:26:48 +01:00
|
|
|
done
|
|
|
|
echo
|
2024-10-12 11:40:31 +01:00
|
|
|
echo -e "${grey}Submodules removed from commit, continuing...${no_color}"
|
|
|
|
|
|
|
|
# If there are no changes to commit after removing submodules, abort to avoid an empty commit
|
|
|
|
if output=$(git status --porcelain) && [ -z "$output" ]; then
|
|
|
|
echo -e "nothing to commit, working tree clean"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
exit 0
|
2017-04-13 08:26:48 +01:00
|
|
|
else
|
|
|
|
echo "No submodules in commit, continuing..."
|
|
|
|
exit 0
|
|
|
|
fi
|