Add initial support for python bindings
[alexxy/gromacs.git] / admin / git-pre-commit
1 #!/bin/bash
2 #
3 # This file is part of the GROMACS molecular simulation package.
4 #
5 # Copyright (c) 2013, by the GROMACS development team, led by
6 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 # and including many others, as listed in the AUTHORS file in the
8 # top-level source directory and at http://www.gromacs.org.
9 #
10 # GROMACS is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public License
12 # as published by the Free Software Foundation; either version 2.1
13 # of the License, or (at your option) any later version.
14 #
15 # GROMACS is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with GROMACS; if not, see
22 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24 #
25 # If you want to redistribute modifications to GROMACS, please
26 # consider that scientific software is very special. Version
27 # control is crucial - bugs must be traceable. We will be happy to
28 # consider code for inclusion in the official distribution, but
29 # derived work must not be called official GROMACS. Details are found
30 # in the README & COPYING files - if they are missing, get the
31 # official version at http://www.gromacs.org.
32 #
33 # To help us fund GROMACS development, we humbly ask that you cite
34 # the research papers on the package. Check out http://www.gromacs.org.
35
36 # This script is intended as a pre-commit hook that optionally runs all
37 # changes through some formatting check.  Currently, it runs uncrustify and
38 # checks copyright headers.
39 #
40 # By default, it does nothing.  To enable the script after copying it to
41 # .git/hooks/pre-commit, you need to set
42 #   git config hooks.uncrustifymode check
43 #   git config hooks.uncrustifypath /path/to/uncrustify
44 # With this configuration, all source files modified in the commit are run
45 # through uncrustify and checked for correct copyright headers
46 # (see admin/uncrustify.sh for how this set of files is determined).
47 # If any file is changed by uncrustify or has other problems, the names of
48 # those files are reported and the commit is prevented.  The issues can be
49 # fixed by running admin/uncrustify.sh manually.
50 #
51 # To disable the hook, you can set
52 #   git config hooks.uncrustifymode off
53 # To disable it temporarily for a commit, set NO_FORMAT_CHECK environment
54 # variable.  For example,
55 #   NO_FORMAT_CHECK=1 git commit -a
56 # You can also run git commit --no-verify, but that also disables other hooks,
57 # such as the Change-Id hook used by gerrit.
58 #
59 # The actual work is done by the admin/uncrustify.sh script, which gets
60 # run with the 'check-index' action.
61 # See the comments in that script for more information.
62
63 if [ ! -z "$NO_FORMAT_CHECK" ]
64 then
65     exit 0
66 fi
67
68 if git rev-parse --verify HEAD >/dev/null 2>&1
69 then
70     against=HEAD
71 else
72     # Initial commit: diff against an empty tree object
73     against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
74 fi
75
76 # Redirect output to stderr.
77 exec 1>&2
78
79 uncrustify_mode=`git config hooks.uncrustifymode`
80 copyright_mode=`git config hooks.copyrightmode`
81 if [ -z "$uncrustify_mode" ]
82 then
83     uncrustify_mode=off
84 fi
85 if [ -z "$copyright_mode" ]
86 then
87     copyright_mode=off
88 fi
89
90 if [[ -f admin/uncrustify.sh && \
91       ( "$uncrustify_mode" != "off" || "$copyright_mode" != "off" ) ]]
92 then
93     if [ "$uncrustify_mode" != "off" ]
94     then
95         uncrustify_path=`git config hooks.uncrustifypath`
96         if [ -z "$uncrustify_path" ]
97         then
98             echo "Please set the path to uncrustify using 'git config hooks.uncrustifypath'."
99             echo "Note that you need a custom version of uncrustify."
100             exit 1
101         fi
102         export UNCRUSTIFY="$uncrustify_path"
103     fi
104     admin/uncrustify.sh check-index --rev=$against \
105         --uncrustify="$uncrustify_mode" --copyright="$copyright_mode"
106     stat=$?
107     if [ $stat -eq 1 ] ; then
108         exit 1
109     elif [ $stat -ne 0 ] ; then
110         echo "Source code formatting check failed"
111         exit 1
112     fi
113 fi