From 1f0ceaa6c76f2a1cba628f238cf23530d006a30a Mon Sep 17 00:00:00 2001 From: Riccardo Schirone Date: Wed, 26 Sep 2018 11:06:04 +0200 Subject: [PATCH] sys/pre-commit-indent.sh: fix return code --- sys/pre-commit-indent.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/sys/pre-commit-indent.sh b/sys/pre-commit-indent.sh index c436fd4d3f..004ac3d26d 100755 --- a/sys/pre-commit-indent.sh +++ b/sys/pre-commit-indent.sh @@ -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."