-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
30 lines (25 loc) · 871 Bytes
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/sh
files=$(git diff-index --name-only --cached HEAD) #get all files inside commit
declare -a filesWithoutEmptyLine
for f in ${files[@]}
do
if [[ "$f" =~ [.](js|cs|config)$ ]]; #filter by expansion
then
ch=$(tail -c1 $f) #get last bite of file
num=$(printf '%d' "'$ch"); #get number of char (it's just duct tape, other don't work on the windows)
if [ $num != 0 ] && [ $num != 10 ]; # 0 - \0, 10 - \n ASCII
then
filesWithoutEmptyLine+=($f) #add file without empty line to array
fi
fi
done
if [ $filesWithoutEmptyLine != "" ] #check for empty
then
printf '%s\n' "xD"
printf '%s\n\t' "You can't commit changes because there is no empty lines in the end of following files:"
for file in ${filesWithoutEmptyLine[@]};
do
printf '%s\n\t' "- $file" #just print our files
done
exit 1; #exit with error
fi