Skip to content
Permalink
Browse files
Merge pull request #6 from web/iss005/prevent-merging-to-master-branch
Iss005/prevent merging to master branch
  • Loading branch information
aa7401 committed Nov 24, 2019
2 parents 3e6c77a + f1e2743 commit b1276e00c5f098340cdc44e9bf3b9b59c3819973
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
@@ -6,6 +6,7 @@ echo "PRE-COMMIT"

EMAIL=$(git config user.email)

# make sure the user has registered a valid university email address
if [[ $EMAIL != *"@coventry.ac.uk" ]]; then
echo " invalid config settings"
echo " Your registered email is currently '$EMAIL'"
@@ -18,13 +19,25 @@ if [[ $EMAIL != *"@coventry.ac.uk" ]]; then
exit 1
fi

# see if the user is trying to merge a branch into master
branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ $2 == 'merge' ]]; then
echo "merging branch"
if [[ "$branch" == "master" ]]; then
echo " trying to merge into the 'master' branch"
echo " you should push the local branch to GitHub"
echo " and merge to master using a pull request"
echo
exit 1
fi
fi

echo " attempting to commit to the '$branch' branch"

# see if the user is trying to commit to the master branch
echo " you are trying to commit to the '$branch' branch"
if [ "$branch" = "master" ]; then
echo " you can't commit directly to the master branch"
echo " create a local feature branch first"
echo
exit 1
fi

@@ -21,7 +21,6 @@ fi

# Current branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo CURRENT_BRANCH

# Check if in PROTECTED_BRANCH
if [[ "$CURRENT_BRANCH" != "$PROTECTED_BRANCH" ]]; then
@@ -30,9 +29,9 @@ if [[ "$CURRENT_BRANCH" != "$PROTECTED_BRANCH" ]]; then
exit 0
fi

echo " you are trying to merge the ${CURRENT_BRANCH} branch into the ${PROTECTED_BRANCH} branch"
echo " you are trying to merge into the ${PROTECTED_BRANCH} branch"
echo " merging branches to master must be done by creating a pull request"
echo " this merge has been cancelled however you will need to"
echo " reset the operation before continuing by running git reset --merge"

echo
exit 1

0 comments on commit b1276e0

Please sign in to comment.