Scripts/git-pre-commit-hook : Tweaks.

This commit is contained in:
Erik de Castro Lopo
2014-04-19 21:17:29 +10:00
parent 080dcdafa5
commit aad4053168
+30 -30
View File
@@ -14,28 +14,16 @@ files=$(git diff-index --name-status --cached HEAD | grep -v ^D | sed -r "s/^[A-
exec 1>&2
#-------------------------------------------------------------------------------
# Check the copyright notice of all files to be commited.
# Prevent files with non-ascii filenames from being committed.
user=`git config --global user.email`
year=`date +"%Y"`
missing_copyright_year=""
if test $user = "erikd@mega-nerd.com" ; then
for f in $files ; do
if test `head -5 $f | grep -c -i copyright` -gt 0 ; then
user_copyright=`grep -i copyright $f | grep $user | grep -c $year`
if test $user_copyright -lt 1 ; then
missing_copyright_year="$missing_copyright_year $f"
fi
fi
done
fi
if test -n "$missing_copyright_year" ; then
echo "Missing current year in the copyright notice of the following files:"
for f in $missing_copyright_year ; do
echo " $f"
done
if test $(git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 ; then
echo "Error: Attempt to add a non-ascii file name."
echo
echo "This can cause problems if you want to work"
echo "with people on other platforms."
echo
echo "To be portable it is advisable to rename the file ..."
echo
echo "Commit aborted."
exit 1
fi
@@ -62,16 +50,28 @@ if test -n "$cfiles" ; then
fi
#-------------------------------------------------------------------------------
# Prevent files with non-ascii filenames from being committed.
# Check the copyright notice of all files to be commited.
if test $(git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 ; then
echo "Error: Attempt to add a non-ascii file name."
echo
echo "This can cause problems if you want to work"
echo "with people on other platforms."
echo
echo "To be portable it is advisable to rename the file ..."
echo
user=`git config --global user.email`
year=`date +"%Y"`
missing_copyright_year=""
if test $user = "erikd@mega-nerd.com" ; then
for f in $files ; do
if test `head -5 $f | grep -i copyright | grep -c -i $user` -gt 0 ; then
user_copyright=`grep -i copyright $f | grep $user | grep -c $year`
if test $user_copyright -lt 1 ; then
missing_copyright_year="$missing_copyright_year $f"
fi
fi
done
fi
if test -n "$missing_copyright_year" ; then
echo "Missing current year in the copyright notice of the following files:"
for f in $missing_copyright_year ; do
echo " $f"
done
echo "Commit aborted."
exit 1
fi