-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpre-receive
More file actions
28 lines (24 loc) · 761 Bytes
/
Copy pathpre-receive
File metadata and controls
28 lines (24 loc) · 761 Bytes
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
#!/bin/sh
# protect branch from pushes by non-authorized users
# Volker Kuhlmann (2017)
# protected branch name
protected_branch="refs/heads/master"
# list of authorized users
authorized_users="Michael|John"
# return value : 0 is OK
return_value=0
# test the query branch against the protected branch
while read oldrev newrev refname ; do
if test "$refname" = "$protected_branch"
then
echo "CHECKS authorization for protected branch" $protected_branch
# test the current user against list of authorized users
if [[ "$GOGS_AUTH_USER_NAME" != +($authorized_users) ]];
then
# return value : 1 is NOT OK
return_value=1
echo "DENIES push to protected branch by" $GOGS_AUTH_USER_NAME
fi
fi
done
exit $return_value