telegram-bot-bash/dev/hooks/pre-commit.sh

41 lines
950 B
Bash
Raw Normal View History

2019-04-18 16:38:20 +00:00
#!/usr/bin/env bash
2019-04-24 15:34:36 +00:00
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
2019-04-18 16:42:42 +00:00
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script
GIT_DIR=$(git rev-parse --git-dir)
cd "$GIT_DIR/.." || exit 1
2019-04-18 16:38:20 +00:00
2019-04-19 11:01:25 +00:00
export HOOKDIR="dev/hooks"
2019-04-19 08:43:06 +00:00
2019-04-18 16:38:20 +00:00
# if any command inside script returns error, exit and return that error
set -e
2019-04-22 18:34:43 +00:00
echo "Running pre-commit hook"
2019-04-18 16:38:20 +00:00
echo "............................"
unset IFS; set -f
2019-04-18 19:11:44 +00:00
# check for shellcheck
if which shellcheck >/dev/null 2>&1; then
2019-04-22 18:34:43 +00:00
echo " Test all scripts with shellcheck ..."
2019-04-18 19:11:44 +00:00
else
echo "Error: shellcheck is not installed. Install shellcheck or delete $0"
exit 1
fi
2019-04-18 16:38:20 +00:00
# run shellcheck before commit
2019-04-19 15:31:01 +00:00
set +f
2019-04-22 18:34:43 +00:00
FILES="$(find ./* -name '*.sh' | grep -v 'dist\/' )"
2019-04-19 15:31:01 +00:00
set -f
FILES="${FILES} $(sed '/^#/d' <"dev/shellcheck.files")"
2019-04-18 16:38:20 +00:00
if [ "$FILES" != "" ]; then
# shellcheck disable=SC2086
2019-04-18 19:11:44 +00:00
shellcheck -x ${FILES} || exit 1
2019-04-22 18:34:43 +00:00
echo " OK"
2019-04-18 16:38:20 +00:00
else
# something went wrong
exit 1
fi