Optimize automation-event process splitting
[ardour.git] / tools / pre-commit
1 #!/bin/sh
2 #
3 # Called by "git commit" with no arguments.  The hook should
4 # exit with non-zero status after issuing an appropriate message if
5 # it wants to stop the commit.
6 #
7 # To enable this hook, copy this file into ~/.git/hooks and make it executable
8
9 if git rev-parse --verify HEAD >/dev/null 2>&1
10 then
11         against=HEAD
12 else
13         # Initial commit: diff against an empty tree object
14         against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
15 fi
16
17 files=`git diff-index --name-only --cached $against`
18
19 cfiles=""
20
21 for f in $files ; do
22     if test `echo $f | egrep -c "\.([ch]|cc)$"` -gt 0 ; then
23         cfiles="$cfiles $f"
24     fi
25 done
26
27 # Redirect output to stderr.
28 exec 1>&2
29
30 #-------------------------------------------------------------------------------
31 # Check the copyright notice of all files to be commited.
32
33 user=`git config --global user.email`
34 year=`date +"%Y"`
35
36 missing_copyright_year=""
37 for f in $cfiles ; do
38         if test ! -f $f ; then
39                 # If file does not exist, it was probably part of a rename or something.
40                 echo > /dev/null
41         elif test `head -5 $f | grep -c -i copyright` -eq 0 ; then
42             missing_copyright="$missing_copyright $f"
43         fi
44 done
45
46 if test -n "$missing_copyright" ; then
47         echo "Missing the copyright notice of the following files:"
48         for f in $missing_copyright ; do
49                 echo "    $f"
50                 done
51         echo "Commit aborted."
52         exit 1
53 fi
54
55 #-------------------------------------------------------------------------------
56 # Check the formatting of all C/C++ files.
57
58 if test -n "$cfiles" ; then
59         tools/cstyle.py $cfiles
60         if test $? -ne 0 ; then
61                 echo
62                 echo "Commit aborted. Fix the above error before trying again."
63                 exit 1
64         fi
65 fi
66
67 exit 0