Imported Upstream version 2.8.11.2
[platform/upstream/cmake.git] / Utilities / Git / pre-commit
1 #!/usr/bin/env bash
2 #=============================================================================
3 # CMake - Cross Platform Makefile Generator
4 # Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
5 #
6 # Distributed under the OSI-approved BSD License (the "License");
7 # see accompanying file Copyright.txt for details.
8 #
9 # This software is distributed WITHOUT ANY WARRANTY; without even the
10 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # See the License for more information.
12 #=============================================================================
13
14 die() {
15   echo 'pre-commit hook failure' 1>&2
16   echo '-----------------------' 1>&2
17   echo '' 1>&2
18   echo "$@" 1>&2
19   exit 1
20 }
21
22 #-------------------------------------------------------------------------------
23 line_too_long=80
24 bad=$(regex=".{$line_too_long}" &&
25 git diff-index --cached HEAD --name-only --diff-filter=AM \
26     --pickaxe-regex -S"$regex" -- 'Source/*.h' 'Source/*.cxx' |
27 while read file; do
28   lines_too_long=$(git diff-index -p --cached HEAD \
29                    --pickaxe-regex -S"$regex" -- "$file")
30   if echo "$lines_too_long" | egrep -q '^\+'"$regex"; then
31     echo "$lines_too_long"
32   fi
33 done)
34 test -z "$bad" ||
35 die 'The following changes add lines too long for our C++ style:
36
37 '"$bad"'
38
39 Use lines strictly less than '"$line_too_long"' characters in C++ code.'
40
41 #-------------------------------------------------------------------------------
42 if test -z "$HOOKS_ALLOW_KWSYS"; then
43   # Disallow changes to KWSys
44   files=$(git diff-index --name-only --cached HEAD -- Source/kwsys) &&
45   if test -n "$files"; then
46     die 'Changes to KWSys files
47
48 '"$(echo "$files" | sed 's/^/  /')"'
49
50 should not be made directly in CMake.  KWSys is kept in its own Git
51 repository and shared by several projects.  Please visit
52
53   http://public.kitware.com/Wiki/KWSys/Git
54
55 to contribute changes directly to KWSys.  Run
56
57   git reset HEAD -- Source/kwsys
58
59 to unstage these changes.  Alternatively, set environment variable
60
61   HOOKS_ALLOW_KWSYS=1
62
63 to disable this check and commit the changes locally.'
64   fi
65 fi