|
@@ -5,8 +5,8 @@
|
|
# run before them.
|
|
# run before them.
|
|
|
|
|
|
# We need dos2unix and recode.
|
|
# We need dos2unix and recode.
|
|
-if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v recode)" ]; then
|
|
|
|
- printf "Install 'dos2unix' and 'recode' to use this script.\n"
|
|
|
|
|
|
+if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v isutf8)" ]; then
|
|
|
|
+ printf "Install 'dos2unix' and 'isutf8' (from the moreutils package) to use this script.\n"
|
|
fi
|
|
fi
|
|
|
|
|
|
set -uo pipefail
|
|
set -uo pipefail
|
|
@@ -36,7 +36,7 @@ while IFS= read -rd '' f; do
|
|
continue
|
|
continue
|
|
fi
|
|
fi
|
|
# Ensure that files are UTF-8 formatted.
|
|
# Ensure that files are UTF-8 formatted.
|
|
- recode UTF-8 "$f" 2> /dev/null
|
|
|
|
|
|
+ isutf8 "$f" >> utf8-validation.txt 2>&1
|
|
# Ensure that files have LF line endings and do not contain a BOM.
|
|
# Ensure that files have LF line endings and do not contain a BOM.
|
|
dos2unix "$f" 2> /dev/null
|
|
dos2unix "$f" 2> /dev/null
|
|
# Remove trailing space characters and ensures that files end
|
|
# Remove trailing space characters and ensures that files end
|
|
@@ -48,17 +48,27 @@ done
|
|
|
|
|
|
git diff --color > patch.patch
|
|
git diff --color > patch.patch
|
|
|
|
|
|
-# If no patch has been generated all is OK, clean up, and exit.
|
|
|
|
-if [ ! -s patch.patch ] ; then
|
|
|
|
|
|
+# If no UTF-8 violations were collected and no patch has been
|
|
|
|
+# generated all is OK, clean up, and exit.
|
|
|
|
+if [ ! -s utf8-validation.txt ] && [ ! -s patch.patch ] ; then
|
|
printf "Files in this commit comply with the formatting rules.\n"
|
|
printf "Files in this commit comply with the formatting rules.\n"
|
|
- rm -f patch.patch
|
|
|
|
|
|
+ rm -f patch.patch utf8-validation.txt
|
|
exit 0
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
|
|
-# A patch has been created, notify the user, clean up, and exit.
|
|
|
|
-printf "\n*** The following differences were found between the code "
|
|
|
|
-printf "and the formatting rules:\n\n"
|
|
|
|
-cat patch.patch
|
|
|
|
|
|
+# Violations detected, notify the user, clean up, and exit.
|
|
|
|
+if [ -s utf8-validation.txt ]
|
|
|
|
+then
|
|
|
|
+ printf "\n*** The following files contain invalid UTF-8 character sequences:\n\n"
|
|
|
|
+ cat utf8-validation.txt
|
|
|
|
+fi
|
|
|
|
+
|
|
|
|
+if [ -s patch.patch ]
|
|
|
|
+then
|
|
|
|
+ printf "\n*** The following differences were found between the code "
|
|
|
|
+ printf "and the formatting rules:\n\n"
|
|
|
|
+ cat patch.patch
|
|
|
|
+fi
|
|
|
|
+rm -f utf8-validation.txt patch.patch
|
|
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
|
|
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
|
|
-rm -f patch.patch
|
|
|
|
exit 1
|
|
exit 1
|