Skip to content

Commit a14f222

Browse files
committed
fix some errors in update server hook
1 parent 50dfc8f commit a14f222

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

serverhooks/update

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ echo "Enforcing policies for revision ${refname}:"
2121
# -------------------------------
2222

2323
# exit if a branch is about to be deleted
24-
if new == '0000000000000000000000000000000000000000':
24+
if [ "${newrev}" == '0000000000000000000000000000000000000000' ]; then
2525
exit 0
26+
fi
2627

2728
# Check if a zero sha, then either a new branch is pushed or an empty repo is being pushed
28-
if [ "${oldrev}" = "0000000000000000000000000000000000000000" ]; then
29+
if [ "${oldrev}" == "0000000000000000000000000000000000000000" ]; then
2930
# List everything reachable from newrev but not any heads
3031
span=`git rev-list $(git for-each-ref --format='%(refname)' refs/heads/* | sed 's/^/\^/') ${newrev}`
3132
else
@@ -35,11 +36,12 @@ fi
3536
# ------------------------------------
3637
# Iterate over all commits in the push
3738
# ------------------------------------
39+
3840
refuse=false
3941
for sha1 in ${span}; do
40-
42+
year=$(git log "${sha1}" --pretty=%cd -n 1| cut -d ' ' -f 5)
4143
# don't check commits from before 2020
42-
if [ 2020 -le "$(git log "${sha1}" --pretty=%cd | cut -d ' ' -f 5)" ]; then
44+
if [ "${year}" -lt '2020' ]; then
4345
continue
4446
fi
4547

@@ -55,40 +57,41 @@ for sha1 in ${span}; do
5557
commitfirstline=$(echo "${commitmessage}" | head -n 1)
5658

5759
# don't check revert commits
60+
# TODO
5861
if [[ "${commitfirstline}" == Revert* ]]; then
5962
continue
6063
fi
6164

6265
# if commitmessage has 2 or more lines, make sure the second line is empty
6366
if [ $(echo "${commitmessage}" | wc -l) -ge 2 ]; then
64-
if [ $(echo "${commitmessage}" | head -n 2 | tail -n 2) != "" ]; then
65-
echo "commit: ${sha1}"
66-
echo "bad commit message: second line is not blank"
67+
if [ "$(echo "${commitmessage}" | head -n 2 | tail -n 2)" != "" ]; then
68+
echo "${sha1} bad commit message; second line is not blank"
6769
refuse=true
6870
fi
6971
fi
7072

7173
# check length of commit description lines
72-
for line in ${commitmessage}; do
74+
while IFS= read -r line; do
7375
if [ 75 -lt $(echo ${line} | wc -c) ]; then
74-
echo "commit: ${sha1}"
75-
echo "bad commit message: header or description lines are too long (max 75 chars)"
76+
echo "${sha1} bad commit message; header or description lines are too long (max 75 chars per line)"
7677
refuse=true
7778
break
7879
fi
79-
done
80+
done <<< "${commitmessage}"
8081

8182
# check for whitespace errors in commit
8283
whitespace=$(exec git diff --check ${sha1}^ ${sha1} *.c *.h *.cpp *.hpp *.sh)
8384
if [ "${whitespace}" != "" ]; then
84-
echo "commit: ${sha1} contains whitespace errors."
85+
echo "${sha1} contains whitespace errors."
8586
refuse=true
8687
fi
8788
done
8889

8990
if [ "${refuse}" == true ]; then
9091
echo "Found errors, please fix them before pushing."
92+
exit 1
9193
else
9294
echo "All good, thank you!"
9395
fi
9496

97+
exit 1

0 commit comments

Comments
 (0)