add precommit hook example
authorng0 <ng0@n0.is>
Sun, 29 Sep 2019 10:30:10 +0000 (10:30 +0000)
committerng0 <ng0@n0.is>
Sun, 29 Sep 2019 10:30:10 +0000 (10:30 +0000)
contrib/uncrustify_precommit [new file with mode: 0644]

diff --git a/contrib/uncrustify_precommit b/contrib/uncrustify_precommit
new file mode 100644 (file)
index 0000000..bf7bac4
--- /dev/null
@@ -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