From dd298ca059ed935560cccfa020127c93b4d3f823 Mon Sep 17 00:00:00 2001 From: ng0 Date: Sun, 29 Sep 2019 10:30:10 +0000 Subject: [PATCH] add precommit hook example --- contrib/uncrustify_precommit | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 contrib/uncrustify_precommit diff --git a/contrib/uncrustify_precommit b/contrib/uncrustify_precommit new file mode 100644 index 000000000..bf7bac4ef --- /dev/null +++ b/contrib/uncrustify_precommit @@ -0,0 +1,34 @@ +#!/bin/sh + +# use as .git/hooks/pre-commit + +exec 1>&2 + +RET=0 + +changed=$(git diff --cached --name-only) +crustified="" + +for f in $changed; +do + # compare result of uncrustify with changes + # + # only change any of the invocations here if + # they are portable across all cmp and shell + # implementations! + uncrustify -q -c uncrustify.cfg -f $f | cmp -s $f - + if test $? = 1 ; + then + crustified=" $crustified $f" + RET=1 + fi +done + +if [ $RET = 1 ]; +then + echo "Run" + echo "uncrustify --no-backup -c uncrustify.cfg ${crustified}" + echo "before commiting." +fi + +exit $RET -- 2.25.1