-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpre-receive
executable file
·65 lines (48 loc) · 1.19 KB
/
pre-receive
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
#!/bin/bash
# 1/ ensure I'm up to date, but do not fail if not
# 2/ check tools presence
NULL_SHA1="0000000000000000000000000000000000000000" # 40 0's
UPTODATE_RUNNED=0
DEBUG=0
TMP_DIR=
TMPTOOLS=/tmp/check_tools
echo "RUN pre-receive hook (https://github.com/ezweb/pre-receive-hook)"
function error()
{
echo ""
echo -e "\033[31m 💥 ERROR 💥 $@ \033[0m"
echo ""
exit 3
}
function debug()
{
if [ $DEBUG -gt 0 ]
then
echo "(debug: $@)"
fi
}
# Run loop as soon as possible, to ensure this is this loop that will handle stdin
while read oldrev newrev ref
do
# in a sub-shell ...
# old revision is blank - branch creation
if [ "$oldrev" = "$NULL_SHA1" ] ||
# new revision is blank - branch deletion
[ "$newrev" = "$NULL_SHA1" ] ;
then
# create new or delete old branch
continue;
fi
# Allow Gitlab online rebase
if grep -q master-patch <<< $ref
then
continue
fi
base=$(git merge-base $oldrev $newrev);
if [ "$base" != "$oldrev" ] && echo $ref | grep -vq "renovate/"
then
# non fast forward merge
error "Force pushing of $ref is forbidden 🤬";
fi
done
exit 0