From d7fb2144ad07b5b3ef93d12de9d2a5a8be719d13 Mon Sep 17 00:00:00 2001 From: Mark Tyers Date: Sun, 24 Nov 2019 22:22:43 +0000 Subject: [PATCH 1/2] Added Check for Merge to Master --- .githooks/pre-commit | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 5a29bd9..f59b810 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -7,25 +7,38 @@ echo "PRE-COMMIT" EMAIL=$(git config user.email) echo $EMAIL +# make sure the user has registered a valid university email address if [[ $EMAIL != *"@coventry.ac.uk" ]]; then echo " invalid config settings" - echo " please input your university username:" - read username - echo " you entered $username" - git config user.email $username@coventry.ac.uk - echo " please input your name as it appears on your student ID card:" - read name - echo " you entered $name" - git config user.name '$name' + echo " Your registered email is currently '$EMAIL'" + echo " please run the following git commands:" + echo " $ git config user.email xxx@coventry.ac.uk" + echo " $ git config user.name 'zzz'" + echo " where 'xxx' is your university username" + echo " and 'zzz' is your name as it appears on your university ID badge" + echo + 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 +# 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 From 85ed47f3cd1f4b76e3e56afcb10dae7bd42c8755 Mon Sep 17 00:00:00 2001 From: Mark Tyers Date: Sun, 24 Nov 2019 22:26:30 +0000 Subject: [PATCH 2/2] Cleaned Up Hooks --- .githooks/post-commit | 1 + .githooks/prepare-commit-msg | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.githooks/post-commit b/.githooks/post-commit index 30cf412..36ee006 100755 --- a/.githooks/post-commit +++ b/.githooks/post-commit @@ -4,3 +4,4 @@ set -e # using the options command to abort script at first error echo echo "POST-COMMIT" # ./node_modules/.bin/markdownlint --ignore node_modules . +echo \ No newline at end of file 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