Pārlūkot izejas kodu

pre-commit: Reject C++ code with lines too long

Check changes in Source/*.h and Source/*.cxx for lines longer than
our style limit.
Brad King 13 gadi atpakaļ
vecāks
revīzija
873f21ad1b
1 mainītis faili ar 20 papildinājumiem un 0 dzēšanām
  1. 20 0
      Utilities/Git/pre-commit

+ 20 - 0
Utilities/Git/pre-commit

@@ -19,6 +19,26 @@ die() {
   exit 1
   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
 if test -z "$HOOKS_ALLOW_KWSYS"; then
   # Disallow changes to KWSys
   # Disallow changes to KWSys
   files=$(git diff-index --name-only --cached HEAD -- Source/kwsys) &&
   files=$(git diff-index --name-only --cached HEAD -- Source/kwsys) &&