diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2015-05-09 13:51:21 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2015-05-09 13:51:21 -0400 |
commit | deeb5652e2603a3977b8436bbb753341ab9e011c (patch) | |
tree | 39abf559e1b5835d0eeeb5cb71888259bb69e8a0 /tools | |
parent | a4a67470018cfc4a6c47076a45b340274ae3e4ce (diff) |
add pre-commit hook for optional (but recommended) use
Diffstat (limited to 'tools')
-rw-r--r-- | tools/pre-commit | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tools/pre-commit b/tools/pre-commit new file mode 100644 index 0000000000..613f6acf95 --- /dev/null +++ b/tools/pre-commit @@ -0,0 +1,67 @@ +#!/bin/sh +# +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, copy this file into ~/.git/hooks and make it executable + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +fi + +files=`git diff-index --name-only --cached $against` + +cfiles="" + +for f in $files ; do + if test `echo $f | egrep -c "\.([ch]|cc)$"` -gt 0 ; then + cfiles="$cfiles $f" + fi +done + +# Redirect output to stderr. +exec 1>&2 + +#------------------------------------------------------------------------------- +# Check the copyright notice of all files to be commited. + +user=`git config --global user.email` +year=`date +"%Y"` + +missing_copyright_year="" +for f in $cfiles ; do + if test ! -f $f ; then + # If file does not exist, it was probably part of a rename or something. + echo > /dev/null + elif test `head -5 $f | grep -c -i copyright` -eq 0 ; then + missing_copyright="$missing_copyright $f" + fi +done + +if test -n "$missing_copyright" ; then + echo "Missing the copyright notice of the following files:" + for f in $missing_copyright ; do + echo " $f" + done + echo "Commit aborted." + exit 1 +fi + +#------------------------------------------------------------------------------- +# Check the formatting of all C/C++ files. + +if test -n "$cfiles" ; then + tools/cstyle.py $cfiles + if test $? -ne 0 ; then + echo + echo "Commit aborted. Fix the above error before trying again." + exit 1 + fi +fi + +exit 0 |