Added more docs and tests to EnumerationArray
[gromacs.git] / admin / git-pre-commit
blobc52d55914837e63b29998f4f7ea81895c729828b
1 #!/bin/bash
3 # This file is part of the GROMACS molecular simulation package.
5 # Copyright (c) 2013,2014,2015,2019, 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=off
70 clangformat_mode=`git config hooks.clangformatmode`
71 copyright_mode=`git config hooks.copyrightmode`
72 if [ -z "$uncrustify_mode" ]
73 then
74 uncrustify_mode=off
76 if [ -z "$clangformat_mode" ]
77 then
78 clangformat_mode=off
80 if [ -z "$copyright_mode" ]
81 then
82 copyright_mode=off
85 if [[ -f admin/uncrustify.sh && \
86 ( "$uncrustify_mode" != "off" ) ]]
87 then
88 uncrustify_path=`git config hooks.uncrustifypath`
89 if [ -z "$uncrustify_path" ]
90 then
91 echo "Please set the path to uncrustify using 'git config hooks.uncrustifypath'."
92 echo "Note that you need a custom version of uncrustify."
93 exit 1
95 export UNCRUSTIFY="$uncrustify_path"
96 admin/uncrustify.sh check-index --rev=$against \
97 --uncrustify="$uncrustify_mode"
98 stat=$?
99 if [ $stat -eq 1 ] ; then
100 exit 1
101 elif [ $stat -ne 0 ] ; then
102 echo "Source code formatting check with uncrustify failed"
103 exit 1
107 if [[ -f admin/clang-format.sh && \
108 ( "$clangformat_mode" != "off" ) ]]
109 then
110 clangformat_path=`git config hooks.clangformatpath`
111 if [ -z "$clangformat_path" ]
112 then
113 echo "Please set the path to clang-format using 'git config hooks.clangformatpath'."
114 exit 1
116 export CLANG_FORMAT="$clangformat_path"
117 admin/clang-format.sh check-index --rev=$against \
118 --format="$clangformat_mode"
119 stat=$?
120 if [ $stat -eq 1 ] ; then
121 exit 1
122 elif [ $stat -ne 0 ] ; then
123 echo "Source code formatting check with clang-format failed"
124 exit 1
128 if [[ -f admin/copyright.sh && \
129 ( "$copyright_mode" != "off" ) ]]
130 then
131 admin/copyright.sh check-index --rev=$against \
132 --copyright="$copyright_mode"
133 stat=$?
134 if [ $stat -eq 1 ] ; then
135 exit 1
136 elif [ $stat -ne 0 ] ; then
137 echo "Copyright information check failed"
138 exit 1