2020-12-14 17:12:57 +00:00
|
|
|
#!/bin/sh
|
2020-09-09 11:03:27 +00:00
|
|
|
|
2020-12-14 17:12:57 +00:00
|
|
|
set -e -f -u
|
2020-07-15 09:49:08 +00:00
|
|
|
|
2021-12-13 12:28:12 +00:00
|
|
|
# Only show interactive prompts if there is a terminal attached. This
|
|
|
|
# should work on all of our supported Unix systems.
|
|
|
|
is_tty='0'
|
|
|
|
if [ -e /dev/tty ]
|
|
|
|
then
|
|
|
|
is_tty='1'
|
|
|
|
fi
|
|
|
|
readonly is_tty
|
|
|
|
|
|
|
|
# prompt is a helper that prompts the user for interactive input if that
|
|
|
|
# can be done. If there is no terminal attached, it sleeps for two
|
|
|
|
# seconds, giving the programmer some time to react, and returns with
|
|
|
|
# a zero exit code.
|
|
|
|
prompt() {
|
|
|
|
if [ "$is_tty" -eq '0' ]
|
|
|
|
then
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
printf 'commit anyway? y/[n]: '
|
|
|
|
read -r ans < /dev/tty
|
|
|
|
|
|
|
|
case "$ans"
|
|
|
|
in
|
|
|
|
('y'|'Y')
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
(''|'n'|'N')
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
(*)
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Warn the programmer about unstaged changes and untracked files, but do
|
|
|
|
# not fail the commit, because those changes might be temporary or for
|
|
|
|
# a different branch.
|
|
|
|
awk_prog='substr($2, 2, 1) != "." { print $9; } $1 == "?" { print $2; }'
|
|
|
|
readonly awk_prog
|
|
|
|
|
|
|
|
unstaged="$( git status --porcelain=2 | awk "$awk_prog" )"
|
|
|
|
readonly unstaged
|
|
|
|
|
|
|
|
if [ "$unstaged" != "" ]
|
|
|
|
then
|
|
|
|
printf 'WARNING: you have unstaged changes:\n\n%s\n\n' "$unstaged"
|
|
|
|
prompt
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Warn the programmer about temporary todos, but do not fail the commit,
|
|
|
|
# because the commit could be in a temporary branch.
|
|
|
|
temp_todos="$( git grep -e 'TODO.*!!' -- ':!scripts/hooks/pre-commit' || : )"
|
|
|
|
readonly temp_todos
|
|
|
|
|
|
|
|
if [ "$temp_todos" != "" ]
|
|
|
|
then
|
|
|
|
printf 'WARNING: you have temporary todos:\n\n%s\n\n' "$temp_todos"
|
|
|
|
prompt
|
|
|
|
fi
|
2021-07-29 14:40:31 +00:00
|
|
|
|
|
|
|
verbose="${VERBOSE:-0}"
|
|
|
|
readonly verbose
|
2021-06-28 15:24:33 +00:00
|
|
|
|
2021-05-19 17:31:20 +00:00
|
|
|
if [ "$( git diff --cached --name-only -- 'client/*.js' )" ]
|
2020-12-14 17:12:57 +00:00
|
|
|
then
|
2021-07-29 14:40:31 +00:00
|
|
|
make VERBOSE="$verbose" js-lint js-test
|
2020-07-15 09:49:08 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-19 17:31:20 +00:00
|
|
|
if [ "$( git diff --cached --name-only -- 'client2/*.js' 'client2/*.ts' 'client2/*.tsx' )" ]
|
2021-01-28 11:02:38 +00:00
|
|
|
then
|
2021-07-29 14:40:31 +00:00
|
|
|
make VERBOSE="$verbose" js-beta-lint js-beta-test
|
2021-01-28 11:02:38 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-19 17:31:20 +00:00
|
|
|
if [ "$( git diff --cached --name-only -- '*.go' '*.mod' '*.sh' 'Makefile' )" ]
|
2020-12-14 17:12:57 +00:00
|
|
|
then
|
2021-07-29 14:40:31 +00:00
|
|
|
make VERBOSE="$verbose" go-os-check go-lint go-test
|
2020-12-14 17:12:57 +00:00
|
|
|
fi
|
2021-01-14 10:48:52 +00:00
|
|
|
|
2021-05-19 17:31:20 +00:00
|
|
|
if [ "$( git diff --cached --name-only -- '*.md' '*.yaml' '*.yml' )" ]
|
|
|
|
then
|
2021-07-29 14:40:31 +00:00
|
|
|
make VERBOSE="$verbose" txt-lint
|
2021-05-19 17:31:20 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$( git diff --cached --name-only -- './openapi/openapi.yaml' )" ]
|
2021-01-14 10:48:52 +00:00
|
|
|
then
|
2021-07-29 14:40:31 +00:00
|
|
|
make VERBOSE="$verbose" openapi-lint
|
2021-01-14 10:48:52 +00:00
|
|
|
fi
|