1
0

pre-commit 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. die() {
  14. echo 'pre-commit hook failure' 1>&2
  15. echo '-----------------------' 1>&2
  16. echo '' 1>&2
  17. echo "$@" 1>&2
  18. exit 1
  19. }
  20. #-------------------------------------------------------------------------------
  21. line_too_long=80
  22. bad=$(regex=".{$line_too_long}" &&
  23. git diff-index --cached HEAD --name-only --diff-filter=AM \
  24. --pickaxe-regex -S"$regex" -- 'Source/*.h' 'Source/*.cxx' |
  25. while read file; do
  26. lines_too_long=$(git diff-index -p --cached HEAD \
  27. --pickaxe-regex -S"$regex" -- "$file")
  28. if echo "$lines_too_long" | egrep -q '^\+'"$regex"; then
  29. echo "$lines_too_long"
  30. fi
  31. done)
  32. test -z "$bad" ||
  33. die 'The following changes add lines too long for our C++ style:
  34. '"$bad"'
  35. Use lines strictly less than '"$line_too_long"' characters in C++ code.'
  36. #-------------------------------------------------------------------------------
  37. if test -z "$HOOKS_ALLOW_KWSYS"; then
  38. # Disallow changes to KWSys
  39. files=$(git diff-index --name-only --cached HEAD -- Source/kwsys) &&
  40. if test -n "$files"; then
  41. die 'Changes to KWSys files
  42. '"$(echo "$files" | sed 's/^/ /')"'
  43. should not be made directly in CMake. KWSys is kept in its own Git
  44. repository and shared by several projects. Please visit
  45. http://public.kitware.com/Wiki/KWSys/Git
  46. to contribute changes directly to KWSys. Run
  47. git reset HEAD -- Source/kwsys
  48. to unstage these changes. Alternatively, set environment variable
  49. HOOKS_ALLOW_KWSYS=1
  50. to disable this check and commit the changes locally.'
  51. fi
  52. fi