mirror of
https://github.com/Nuitka/Nuitka.git
synced 2026-10-16 02:51:19 +02:00
186 lines
4.7 KiB
Bash
186 lines
4.7 KiB
Bash
#!/bin/sh
|
|
#
|
|
# To enable this hook, execute "python misc/install-git-hooks.py". It
|
|
# makes sure pushed code is checked.
|
|
|
|
# Redirect output to stderr.
|
|
exec 1>&2
|
|
|
|
if [ "$COMMIT_UNCHECKED" = "1" ]
|
|
then
|
|
exit 0
|
|
fi
|
|
|
|
# Set to 0 by the hook installer for repositories that cannot be code spell
|
|
# checked, e.g. Nuitka-Website.
|
|
has_codespell_check=1
|
|
|
|
has_errors=0
|
|
|
|
while read local_ref local_oid remote_ref remote_oid
|
|
do
|
|
case "$local_ref" in
|
|
refs/tags/*)
|
|
continue
|
|
;;
|
|
esac
|
|
|
|
if [ "$local_oid" = "0000000000000000000000000000000000000000" ]
|
|
then
|
|
continue
|
|
fi
|
|
|
|
if [ "$remote_oid" = "0000000000000000000000000000000000000000" ]
|
|
then
|
|
against=""
|
|
for base_branch in "$1/develop" "$1/main" "origin/develop" "origin/main"
|
|
do
|
|
against=$(git merge-base "$local_oid" "$base_branch" 2>/dev/null)
|
|
if [ -n "$against" ]
|
|
then
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ -z "$against" ]
|
|
then
|
|
against="4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
|
fi
|
|
else
|
|
against="$remote_oid"
|
|
fi
|
|
|
|
# spell-checker: ignore ACMR
|
|
files=$(git diff --name-only --diff-filter=ACMR $against..$local_oid)
|
|
|
|
if [ -z "$files" ]
|
|
then
|
|
continue
|
|
fi
|
|
|
|
python_files=""
|
|
c_j2_files=""
|
|
py_j2_files=""
|
|
spell_files=""
|
|
all_files=""
|
|
has_specialize_tool=0
|
|
|
|
for file in $files
|
|
do
|
|
if ! [ -f "$file" ]
|
|
then
|
|
continue
|
|
fi
|
|
|
|
all_files="$all_files $file"
|
|
|
|
case "$file" in
|
|
*.py)
|
|
python_files="$python_files $file"
|
|
;;
|
|
*.c.j2)
|
|
c_j2_files="$c_j2_files $file"
|
|
;;
|
|
*.py.j2)
|
|
py_j2_files="$py_j2_files $file"
|
|
;;
|
|
esac
|
|
|
|
case "$file" in
|
|
nuitka/tools/specialize/*)
|
|
has_specialize_tool=1
|
|
;;
|
|
esac
|
|
|
|
case "$file" in
|
|
*.py | *.scons | *.rst | *.txt | *.j2 | *.md | *.c | *.h)
|
|
spell_files="$spell_files $file"
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -n "$all_files" ]
|
|
then
|
|
OPTIONS="--check --assume-yes-for-downloads"
|
|
|
|
if [ -f "bin/autoformat-nuitka-source" ]
|
|
then
|
|
./bin/autoformat-nuitka-source $OPTIONS $all_files
|
|
if [ $? -ne 0 ]; then has_errors=1; fi
|
|
else
|
|
python -m pipenv run python Nuitka-develop/bin/autoformat-nuitka-source $OPTIONS $all_files
|
|
if [ $? -ne 0 ]; then has_errors=1; fi
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$python_files" ]
|
|
then
|
|
if [ -f "bin/check-nuitka-with-pylint" ]
|
|
then
|
|
./bin/check-nuitka-with-pylint --assume-yes-for-downloads $python_files
|
|
if [ $? -ne 0 ]; then has_errors=1; fi
|
|
else
|
|
python -m pipenv run python Nuitka-develop/bin/check-nuitka-with-pylint --assume-yes-for-downloads $python_files
|
|
if [ $? -ne 0 ]; then has_errors=1; fi
|
|
fi
|
|
fi
|
|
|
|
if [ "$has_codespell_check" = "1" ] && [ -n "$spell_files" ]
|
|
then
|
|
if [ -f "bin/check-nuitka-with-codespell" ]
|
|
then
|
|
./bin/check-nuitka-with-codespell --assume-yes-for-downloads $spell_files
|
|
if [ $? -ne 0 ]; then has_errors=1; fi
|
|
else
|
|
python -m pipenv run python Nuitka-develop/bin/check-nuitka-with-codespell --assume-yes-for-downloads $spell_files
|
|
if [ $? -ne 0 ]; then has_errors=1; fi
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$c_j2_files" ] || [ "$has_specialize_tool" = "1" ]
|
|
then
|
|
if [ "$has_specialize_tool" = "1" ]
|
|
then
|
|
c_args=""
|
|
else
|
|
c_args="$c_j2_files"
|
|
fi
|
|
|
|
if [ -f "bin/generate-specialized-c-code" ]
|
|
then
|
|
./bin/generate-specialized-c-code --check $c_args
|
|
if [ $? -ne 0 ]; then has_errors=1; fi
|
|
else
|
|
python -m pipenv run python Nuitka-develop/bin/generate-specialized-c-code --check $c_args
|
|
if [ $? -ne 0 ]; then has_errors=1; fi
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$py_j2_files" ] || [ "$has_specialize_tool" = "1" ]
|
|
then
|
|
if [ "$has_specialize_tool" = "1" ]
|
|
then
|
|
py_args=""
|
|
else
|
|
py_args="$py_j2_files"
|
|
fi
|
|
|
|
if [ -f "bin/generate-specialized-python-code" ]
|
|
then
|
|
./bin/generate-specialized-python-code --check $py_args
|
|
if [ $? -ne 0 ]; then has_errors=1; fi
|
|
else
|
|
python -m pipenv run python Nuitka-develop/bin/generate-specialized-python-code --check $py_args
|
|
if [ $? -ne 0 ]; then has_errors=1; fi
|
|
fi
|
|
fi
|
|
done
|
|
|
|
if [ "$has_errors" = "1" ]
|
|
then
|
|
echo "Error, pre-push checks failed."
|
|
exit 1
|
|
fi
|
|
|
|
exit 0
|