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:
commit
05adbd718d
|
@ -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
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in New Issue