diff --git a/.githooks/pre-commit b/.githooks/pre-commit index c8593af..f7fbefd 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -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 diff --git a/.githooks/prepare-commit-msg b/.githooks/prepare-commit-msg index bd02a0a..60c7dec 100755 --- a/.githooks/prepare-commit-msg +++ b/.githooks/prepare-commit-msg @@ -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