File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,32 @@ if [ "${whitespace}" != "" ]; then
4545 exit 1
4646fi
4747
48+
49+ # Files (not deleted) in the index
50+ files=$( git diff-index --cached --name-only --diff-filter=d " $against " )
51+ result=0 # track exit code
52+ if [ -n " $files " ]; then
53+ for f in $files ; do
54+ # Only report known text files...
55+ if [ -z " $( git diff-index --cached --stat=1 " $against " " $f " | grep -is ' | Bin' ) " ]; then
56+ # Only match regular files (e.g. no symlinks)
57+ # See: https://stackoverflow.com/a/8347325
58+ if [ " $( git ls-files --stage " $f " | awk ' {print $1}' | head -c2 - ) " = " 10" ]; then
59+ # Using staged version of file instead of working dir
60+ # See: http://stackoverflow.com/a/5032436/5343341
61+ if [ -n " $( git cat-file blob " $( git ls-files --stage " $f " | awk ' {print $2}' ) " | tail -c1 - ) " ]; then
62+ # Report error
63+ if [ " $result " -lt " 1" ]; then
64+ echo " Error: The following files have no trailing newline:"
65+ fi
66+ echo " $f "
67+ exit 1
68+ fi
69+ fi
70+ fi
71+ done
72+ fi
73+
4874# check for `#if 0` in the code
4975ifzeros=$( git diff --cached HEAD * .c * .h * .cpp * .hpp * .sh | grep " ^+" | grep " #if[[:space:]]\+0" )
5076echo " > Checking occurences of '#if 0'."
You can’t perform that action at this time.
0 commit comments