Skip to content

Commit 018e277

Browse files
authored
Add pre-push hook when pushing to develop, trunk and release branches (#2390)
* Add pre-push hook when pushing to develop, trunk and release branches
1 parent 3432fcc commit 018e277

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

.husky/pre-push

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
RED="\033[1;31m"
5+
NO_COLOR="\033[0m"
6+
7+
BRANCH=`git rev-parse --abbrev-ref HEAD`
8+
PROTECTED_BRANCHES="^(trunk|develop|release/*)"
9+
10+
# Only show warning for 'develop', 'trunk' and 'release/...' branches.
11+
if ! [[ "$BRANCH" =~ $PROTECTED_BRANCHES ]]; then
12+
exit 0
13+
fi
14+
15+
# Ask for confirmation, anything other than 'y' or 'Y' is considered as a NO.
16+
echo "\nYou're about to push to ${RED}${BRANCH}${NO_COLOR} 😱, is that what you intended? [y|n] \c"
17+
read -n 1 -r < /dev/tty
18+
echo "\n"
19+
if echo $REPLY | grep -E '^[Yy]$' > /dev/null; then
20+
exit 0
21+
fi
22+
23+
exit 1

0 commit comments

Comments
 (0)