diff --git a/bin/pre-push.sh b/bin/pre-push.sh new file mode 100755 index 0000000000000..60797d34adb94 --- /dev/null +++ b/bin/pre-push.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +PROTECTED_BRANCH="master" +REMOTE_REF=$(echo $HUSKY_GIT_STDIN | cut -d " " -f 3) + +if [[ "$REMOTE_REF" == *"$PROTECTED_BRANCH"* ]]; then + printf "$(tput setaf 3)You're about to push to master, is that what you intended? [y/N]: $(tput sgr0)" + read -r PROCEED < /dev/tty + echo + + if [ "$(echo "${PROCEED:-n}" | tr "[:upper:]" "[:lower:]")" = "y" ]; then + echo "$(tput setaf 2)Brace yourself! Pushing to the master branch...$(tput sgr0)" + echo + exit 0 + fi + + echo "$(tput setaf 2)Push to master cancelled!$(tput sgr0)" + echo + exit 1 +fi diff --git a/package.json b/package.json index b57586e3d5892..157445986018a 100644 --- a/package.json +++ b/package.json @@ -77,8 +77,9 @@ }, "husky": { "hooks": { + "post-merge": "./bin/post-merge.sh", "pre-commit": "lint-staged", - "post-merge": "./bin/post-merge.sh" + "pre-push": "./bin/pre-push.sh" } }, "lint-staged": {