uncrustify_precommit 652 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/sh
  2. # use as .git/hooks/pre-commit
  3. exec 1>&2
  4. RET=0
  5. changed=$(git diff --cached --name-only)
  6. crustified=""
  7. for f in $changed;
  8. do
  9. if echo $f | grep \\.[c,h]\$ > /dev/null
  10. then
  11. # compare result of uncrustify with changes
  12. #
  13. # only change any of the invocations here if
  14. # they are portable across all cmp and shell
  15. # implementations !
  16. uncrustify -q -c uncrustify.cfg -f $f | cmp -s $f -
  17. if test $? = 1 ;
  18. then
  19. crustified=" $crustified $f"
  20. RET=1
  21. fi
  22. fi
  23. done
  24. if [ $RET = 1 ];
  25. then
  26. echo "Run"
  27. echo "uncrustify --no-backup -c uncrustify.cfg ${crustified}"
  28. echo "before commiting."
  29. fi
  30. exit $RET