2011-10-24 18:18:36 +04:00
|
|
|
#!/usr/bin/env bash
|
2016-09-27 22:01:08 +03:00
|
|
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
2011-10-24 18:18:36 +04:00
|
|
|
|
|
|
|
die() {
|
|
|
|
echo 'pre-commit hook failure' 1>&2
|
|
|
|
echo '-----------------------' 1>&2
|
|
|
|
echo '' 1>&2
|
|
|
|
echo "$@" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2012-07-17 16:16:12 +04:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
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.'
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
2011-10-24 18:36:15 +04:00
|
|
|
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/^/ /')"'
|
|
|
|
|
2012-10-05 18:01:14 +04:00
|
|
|
should not be made directly in CMake. KWSys is kept in its own Git
|
|
|
|
repository and shared by several projects. Please visit
|
2011-10-24 18:36:15 +04:00
|
|
|
|
2012-10-05 18:01:14 +04:00
|
|
|
http://public.kitware.com/Wiki/KWSys/Git
|
2011-10-24 18:36:15 +04:00
|
|
|
|
2012-10-05 18:01:14 +04:00
|
|
|
to contribute changes directly to KWSys. Run
|
2011-10-24 18:36:15 +04:00
|
|
|
|
2012-10-05 18:01:14 +04:00
|
|
|
git reset HEAD -- Source/kwsys
|
2011-10-24 18:36:15 +04:00
|
|
|
|
2012-10-05 18:01:14 +04:00
|
|
|
to unstage these changes. Alternatively, set environment variable
|
2011-10-24 18:36:15 +04:00
|
|
|
|
|
|
|
HOOKS_ALLOW_KWSYS=1
|
|
|
|
|
|
|
|
to disable this check and commit the changes locally.'
|
|
|
|
fi
|
|
|
|
fi
|