Skip to content

Commit

Permalink
Added pre-push hook to prevent accidental pushes to master
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosanches committed Jun 10, 2020
1 parent c680f88 commit d3b8e4f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions bin/pre-push.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit d3b8e4f

Please sign in to comment.