forked from wxh794708907/E-Books
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pre-commit
46 lines (40 loc) · 1.01 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
#!/bin/sh
MAX_SIZE=98*1000*1000
export TOP_PID=$$
trap 'exit 1' TERM
SolveBigFile(){
file_size=$(stat -c %s "${1}")
if [[ $file_size -gt $MAX_SIZE ]]; then
file_size=$(awk 'BEGIN{printf "%.2f\n",'$file_size'/'1000000'}')
echo "The file is too large."
echo " File Name: ${1}"
echo " File Size: ${file_size} MB"
echo "Solution: git reset HEAD <file> and rm <file>"
git reset "${1}"
rm "${1}"
return 1
else
return 0
fi
}
for file in ./*
do
if test -f "${file}"
then
SolveBigFile "${file}"
fi
if test -d "${file}"
then
ls "${file}" | while read sub_file
do
if test -d "${sub_file}"; then
echo "error: the directory has sub dir."
exit 1
fi
SolveBigFile "${file}/${sub_file}"
if [ 1 -eq $? ]; then
kill -s TERM $TOP_PID
fi
done
fi
done