File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ #
4
+ # Pre-receive hook that will block any new commits that their names do not being with the userID
5
+ #
6
+ # More details on pre-receive hooks and how to apply them can be found on
7
+ # https://help.github.com/enterprise/admin/guides/developer-workflow/managing-pre-receive-hooks-on-the-github-enterprise-appliance/
8
+ #
9
+
10
+ zero_commit=" 0000000000000000000000000000000000000000"
11
+
12
+ while read oldrev newrev refname; do
13
+ # Only check new branches ($oldrev is zero commit), don't block tags
14
+ if [[ $oldrev == $zero_commit && $refname =~ ^refs/heads/ ]]; then
15
+ # Check if the branch name begins with the userID - NOTE THIS IS CASE SENSITIVE AT THE MOMENT
16
+ if [[ ! $refname =~ ^refs/heads/$GITHUB_USER_LOGIN ]]; then
17
+ echo " Hi, $GITHUB_USER_LOGIN Blocking creation of new branch $refname "
18
+ echo " because it does not start with your username ($GITHUB_USER_LOGIN )"
19
+ echo " as outlined in the branch naming policy guide"
20
+ exit 1
21
+ fi
22
+ fi
23
+ done
24
+ # The following echoes may be enabled if you like. They are a purely a cosmetic
25
+ # demo item to show that it does not have to be just error messages passed back.
26
+ # echo "Hi $GITHUB_USER_LOGIN, allowing creation of new branch $refname"
27
+ # echo "because it does start with your username ($GITHUB_USER_LOGIN)"
28
+ # echo "as outlined in the branch naming policy guide - thank you!"
29
+ exit 0
You can’t perform that action at this time.
0 commit comments