1717refname=$1 # name of ref that is being updated
1818oldrev=$2 # old object name that ref pointed to before
1919newrev=$3 # new object name that ref should point to
20+ nullsha=" 0000000000000000000000000000000000000000"
21+ emptysha=$( git hash-object -t tree /dev/null) # SHA1: "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
22+
2023echo " Enforcing policies for revision ${refname} :"
2124
2225# -------------------------------
2326# Get the list of all the commits
2427# -------------------------------
2528
2629# exit if a branch is about to be deleted
27- if [ " ${newrev} " == ' 0000000000000000000000000000000000000000 ' ]; then
30+ if [ " ${newrev} " == " ${nullsha} " ]; then
2831 exit 0
2932fi
3033
31- checksince=" --since=2020-04-27"
34+ # Set oldrev properly if the is branch created
35+ if [ " ${oldrev} " = " ${nullsha} " ]; then
36+ oldrev=$emptysha
37+ fi
38+
39+ checkmessagesince=" --since=2020-04-27"
40+ checksizesince=" --since=2020-04-13"
41+ sizelimit=52428800
3242
3343# branch labels are updated *after* the hook ran successfully,
34- # so get all commits reachable from newref (that are newer than a certain date),
44+ # so get all commits reachable from newrev (that are newer than a certain date),
3545# that are not reachable from any yet known ref (branch) labels
36- span=$( git rev-list ${newrev} ${checksince } --not --all)
46+ span=$( git rev-list ${newrev} ${checkmessagesince } --not --all)
3747
3848# ----------------------------------------
3949# Iterate over all new commits in the push
@@ -54,6 +64,23 @@ for sha1 in ${span}; do
5464 continue
5565 fi
5666
67+ # check the filesize of each file stays below sizelimit
68+ # list new or modified files
69+ newfiles=$( git show --pretty=" format:" --name-only --diff-filter=ACMRT ${sha1} )
70+
71+ for file in ${newfiles} ; do
72+ size=$( git cat-file -s " ${sha1} :${file} " )
73+ if [[ -z $size ]]; then
74+ size=0;
75+ fi
76+
77+ if [ " ${size} " -gt " ${sizelimit} " ]
78+ then
79+ echo " ${sha1} hard size limit (${sizelimit} ) exceeded: ${file} (${size} bytes)"
80+ refuse=true
81+ fi
82+ done
83+
5784 # check commit message
5885 commitmessage=$( git log --format=%B -n 1 ${sha1} )
5986 commitfirstline=$( echo " ${commitmessage} " | head -n 1)
0 commit comments