summaryrefslogtreecommitdiff
path: root/Utilities/Git/pre-commit
blob: d308a81b5d384f587ef86cfb3ee60980e6372da9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
#=============================================================================
# CMake - Cross Platform Makefile Generator
# Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================

die() {
  echo 'pre-commit hook failure' 1>&2
  echo '-----------------------' 1>&2
  echo '' 1>&2
  echo "$@" 1>&2
  exit 1
}

#-------------------------------------------------------------------------------
line_too_long=80
bad=$(regex=".{$line_too_long}" &&
git diff-index --cached HEAD --name-only --diff-filter=AM \
    --pickaxe-regex -S"$regex" -- 'Source/*.h' 'Source/*.cxx' |
while read file; do
  lines_too_long=$(git diff-index -p --cached HEAD \
                   --pickaxe-regex -S"$regex" -- "$file")
  if echo "$lines_too_long" | egrep -q '^\+'"$regex"; then
    echo "$lines_too_long"
  fi
done)
test -z "$bad" ||
die 'The following changes add lines too long for our C++ style:

'"$bad"'

Use lines strictly less than '"$line_too_long"' characters in C++ code.'

#-------------------------------------------------------------------------------
if test -z "$HOOKS_ALLOW_KWSYS"; then
  # Disallow changes to KWSys
  files=$(git diff-index --name-only --cached HEAD -- Source/kwsys) &&
  if test -n "$files"; then
    die 'Changes to KWSys files

'"$(echo "$files" | sed 's/^/  /')"'

cannot be committed through Git.  KWSys is kept in a CVS repository
shared by several projects.  A robot replays changes committed there
into the Source/kwsys directory in CMake.  Please send changes to
this directory separately.  Run

  git reset HEAD -- Source/kwsys

to unstage these changes and then

  git diff -- Source/kwsys > kwsys.patch

to construct the patch.  Alternatively, set environment variable

  HOOKS_ALLOW_KWSYS=1

to disable this check and commit the changes locally.'
  fi
fi