mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 01:03:23 +03:00
e11636b6f8
refs https://ghost.slack.com/archives/C02G9E68C/p1665497363885949 - we've seen an issue with `lint-staged` in the Admin package because it doesn't pick up the lint-todo file, so it incorrectly flags linting issues that we're ignoring - this is happening because it runs the command from cwd, where the lint exclusion file does not exist - thankfully, `lint-staged` has `--relative` which will run the command from the directory where the command is defined in config, so `ghost/admin` in our case, and that means the lint file is present and picked up
51 lines
1.2 KiB
Bash
Executable File
51 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Modified from https://github.com/chaitanyagupta/gitutils
|
|
|
|
[ -n "$CI" ] && exit 0
|
|
|
|
yarn lint-staged --relative
|
|
lintStatus=$?
|
|
|
|
if [ $lintStatus -ne 0 ]; then
|
|
echo "❌ Linting failed"
|
|
exit 1
|
|
fi
|
|
|
|
green='\033[0;32m'
|
|
no_color='\033[0m'
|
|
grey='\033[0;90m'
|
|
|
|
|
|
ROOT_DIR=$(git rev-parse --show-cdup)
|
|
SUBMODULES=$(grep path ${ROOT_DIR}.gitmodules | sed 's/^.*path = //')
|
|
MOD_SUBMODULES=$(git diff --cached --name-only | grep -F "$SUBMODULES")
|
|
|
|
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
|
|
echo -n -e "Continue with commit? ${grey}(N|y)${no_color} "
|
|
read -n 1 reply </dev/tty
|
|
echo
|
|
if [[ "$reply" == "y" || "$reply" == "Y" ]]; then
|
|
echo "Permitting submodules to be committed..."
|
|
exit 0
|
|
else
|
|
echo "Aborting commit due to submodule update."
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "No submodules in commit, continuing..."
|
|
exit 0
|
|
fi
|