Merge branch release-5-1
[gromacs.git] / admin / git-pre-commit
blobe067c07590395e5d5e20ca9bc145acc2f09c80e7
1 #!/bin/bash
3 # This file is part of the GROMACS molecular simulation package.
5 # Copyright (c) 2013,2014,2015, 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.
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.
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.
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.
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.
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.
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.
40 # It needs to be copied as .git/hooks/pre-commit and configured with
41 # git config hooks.uncrustifypath /path/to/uncrustify
42 # git config hooks.uncrustifymode check
43 # git config hooks.copyrightmode update
45 # To disable the hook temporarily for a commit, set NO_FORMAT_CHECK environment
46 # variable. For example,
47 # NO_FORMAT_CHECK=1 git commit -a
48 # You can also run git commit --no-verify, but that also disables other hooks,
49 # such as the Change-Id hook used by Gerrit.
51 # See docs/dev-manual/uncrustify.rst for more details.
53 if [ ! -z "$NO_FORMAT_CHECK" ]
54 then
55 exit 0
58 if git rev-parse --verify HEAD >/dev/null 2>&1
59 then
60 against=HEAD
61 else
62 # Initial commit: diff against an empty tree object
63 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
66 # Redirect output to stderr.
67 exec 1>&2
69 uncrustify_mode=`git config hooks.uncrustifymode`
70 copyright_mode=`git config hooks.copyrightmode`
71 if [ -z "$uncrustify_mode" ]
72 then
73 uncrustify_mode=off
75 if [ -z "$copyright_mode" ]
76 then
77 copyright_mode=off
80 if [[ -f admin/uncrustify.sh && \
81 ( "$uncrustify_mode" != "off" || "$copyright_mode" != "off" ) ]]
82 then
83 if [ "$uncrustify_mode" != "off" ]
84 then
85 uncrustify_path=`git config hooks.uncrustifypath`
86 if [ -z "$uncrustify_path" ]
87 then
88 echo "Please set the path to uncrustify using 'git config hooks.uncrustifypath'."
89 echo "Note that you need a custom version of uncrustify."
90 exit 1
92 export UNCRUSTIFY="$uncrustify_path"
94 admin/uncrustify.sh check-index --rev=$against \
95 --uncrustify="$uncrustify_mode" --copyright="$copyright_mode"
96 stat=$?
97 if [ $stat -eq 1 ] ; then
98 exit 1
99 elif [ $stat -ne 0 ] ; then
100 echo "Source code formatting check failed"
101 exit 1