aboutsummaryrefslogtreecommitdiff
path: root/contrib/uncrustify_precommit
blob: a370277cce2f303202fe4ce1fc669089b1cafee2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/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
      if echo $f | grep \\.[c,h]\$ > /dev/null
      then
        crustified=" $crustified $f"
        RET=1
      fi
  fi
done

if [ $RET = 1 ];
then
  echo "Run"
  echo "uncrustify --no-backup -c uncrustify.cfg ${crustified}"
  echo "before commiting."
fi
exit $RET