From d3b8e4f66aa6ed8757c9edce93db9e15d3b124d5 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 10 Jun 2020 00:40:48 -0300 Subject: [PATCH] Added pre-push hook to prevent accidental pushes to master --- bin/pre-push.sh | 20 ++++++++++++++++++++ package.json | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 bin/pre-push.sh 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": {