This repository was archived by the owner on Feb 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
78 lines (74 loc) · 1.85 KB
/
pre-commit
File metadata and controls
78 lines (74 loc) · 1.85 KB
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
#!/bin/bash
#for wamp installs
for i in $(ls -a /c/wamp/bin/php|cat)
do
result=$i
done
export PATH=$PATH:/c/wamp/bin/php/$result
errors=0
files=0
ignored=0
for i in $(git diff-index --name-only --cached HEAD)
do
echo $i
if [ ! -f $i ]; then #if file doesn't exist, it was probably flagged for deletion.
continue
fi
files=$((files+1))
result=$(echo $i | perl -ne "/(Thumbs\.db|\.DS_Store|\._.*)$/ && print")
if [ -n "$result" ]; then #string wasn't empty - so we don't want this file.
#some files shouldn't be commited
errors=$((errors+1))
echo "$i is a gunk file. Add it to .gitignore"
continue;
fi
#check file for /*FIX*/ - these are marks for code that shouldn't be commited.
output=$(grep -in "/\*FIX\*/" $i)
if [ $output ]; then
echo $i contains FIX marks:
echo $output
errors=$((errors+1))
fi
#break up the file for the extention
filename=$(basename $i)
extension=${filename##*.}
filename=${filename%.*}
case "$extension" in
css) #Cascading style sheets.
if [ $(awk '{c+=gsub(s,s)}END{print c}' s='{' $i) != $(awk '{c+=gsub(s,s)}END{print c}' s='}' $i) ]; then
echo '$i has unbalanced braces.'
errors=$((errors+1))
fi
;;
php) #PHP
output=$(php -d display_errors=1 -l $i 2>/dev/null)
if [ "$output" != "No syntax errors detected in $i" ]; then
echo $output
errors=$((errors+1))
fi
;;
# pl) #Perl
# output=$(perl -Mstrict -Mdiagnostics -cw)
# if [ "$output" != "- syntax OK" ]; then
# echo $output
# errors=$((errors+1))
# fi
# ;;
rb)# RUBY
output=$(ruby -c $i 2>&1)
if [ $? -ne 0 ]; then
echo $output
errors=$((errors+1))
fi
;;
*) #ignore file
ignored=$((ignored+1))
esac
done
echo ""
echo "Files checked:" $files "| Errors found:" $errors "| Files ignored:" $ignored
if [ $errors = 0 ]; then
exit 0
else
exit 1
fi