sys/pre-commit-indent.sh: fix return code

This commit is contained in:
Riccardo Schirone 2018-09-26 11:06:04 +02:00
parent 58ae11607a
commit 1f0ceaa6c7

View File

@ -7,6 +7,19 @@
#
# To enable this hook, move it to ".git/hooks/pre-commit".
restore_exit() {
git apply < "${UNSTAGED_DIFF}" 2>/dev/null
rm -f "${TMPFILE}"
rm -f "${UNSTAGED_DIFF}"
if [ "$#" -ne 1 ] ; then
exit 1
else
exit $1
fi
}
trap restore_exit 1 2 6
TMPFILE="$(mktemp)"
if [ -z "$TMPFILE" ] ; then
echo "mktemp returned an empty string for \"TMPFILE\"."
@ -23,13 +36,6 @@ git diff > ${UNSTAGED_DIFF} || exit 1
git checkout -- . || exit 1
git diff --cached | ./sys/clang-format-diff.py -p1 > "${TMPFILE}"
restore_exit() {
git apply < "${UNSTAGED_DIFF}" 2>/dev/null
rm -f "${TMPFILE}"
rm -f "${UNSTAGED_DIFF}"
exit 1
}
if [ -s "${TMPFILE}" ] ; then
echo "Please follow the coding style!"
echo "Run \`git diff --cached | ./sys/clang-format-diff.py -p1 -i\` to apply the changes listed below and remember to add them to git."