-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
executable file
·84 lines (69 loc) · 1.47 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
function check_style {
# No tab characters allowed.
#
if grep -q $'\t' $1
then
grep -C 1 --color=auto $'\t' $1
echo "File $1 contains tab character."
exit 1
fi
# Correct would be \r\n but \r should not occurr.
#
if grep -q $'\r' $1
then
grep -C 1 --color=auto $'\r' $1
echo "ERROR: File $1 contains Windows line endings."
exit 1
fi
# Do not allow => character sequence
#
if grep -q "=>" $1
then
grep -C 1 --color=auto "=>" $1
echo "ERROR: File $1 contains \"=>\" instead of \"⇒\"."
exit 1
fi
# Do not allow <- character sequence.
#
if grep -q "<-" $1
then
grep -C 1 --color=auto "<-" $1
echo "ERROR: File $1 contains \"<-\" instead of \"←\"."
exit 1
fi
# File must end in new line.
if [ "`tail -c 1 $1`" != "" ]
then
echo "ERROR: File $1 does not end with \\n."
exit 1
fi
}
#
# This is what you could use to check all files in the repo.
#
#for file in `find . -iname *.scala -type f` ; do
# check_style $file
#done
#
#
# Git pre-commit hook stuff behaviour
#
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
files=$(git diff-index --name-status --cached $against | grep -v ^D | cut -c3-)
if [ "$files" != "" ]
then
for file in $files
do
if [[ "$file" =~ [.]scala$ ]]
then
check_style $file
fi
done
fi