Merge pull request #26742 from woocommerce/update/git-hook-pre-push

Added pre-push hook to prevent accidental pushes to master
This commit is contained in:
Christopher Allford 2020-06-21 11:28:00 -07:00 committed by GitHub
commit 05adbd718d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

22
bin/pre-push.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/sh
PROTECTED_BRANCH="master"
REMOTE_REF=$(echo "$HUSKY_GIT_STDIN" | cut -d " " -f 3)
if [ -n "$REMOTE_REF" ]; then
if [ -z "${REMOTE_REF##*$PROTECTED_BRANCH*}" ]; then
printf "%sYou're about to push to master, is that what you intended? [y/N]: %s" "$(tput setaf 3)" "$(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
fi

View File

@ -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": {