[go: nahoru, domu]

Skip to content

Commit

Permalink
Fix bin/post-merge.sh & bin/pre-push.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
chihsuan committed Apr 6, 2022
1 parent ae44908 commit 7c4c98c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .husky/post-push → .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

./bin/post-push.sh
./bin/pre-push.sh
4 changes: 3 additions & 1 deletion bin/post-merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ runOnChange() {
fi
}

runOnChange "package-lock.json" "pnpm install"
runOnChange "pnpm-lock.yaml" "pnpm install"
runOnChange "composer.lock" "SKIP_UPDATE_TEXTDOMAINS=true composer install"
runOnChange "plugins/woocommerce/composer.lock" "SKIP_UPDATE_TEXTDOMAINS=true composer --working-dir=plugins/woocommerce install"
runOnChange "plugins/woocommerce-beta-tester/composer.lock" "SKIP_UPDATE_TEXTDOMAINS=true composer --working-dir=plugins/woocommerce-beta-tester install"
35 changes: 16 additions & 19 deletions bin/pre-push.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
#!/bin/sh

PROTECTED_BRANCH="trunk"
REMOTE_REF=$(echo "$HUSKY_GIT_STDIN" | cut -d " " -f 3)

if [ -n "$REMOTE_REF" ]; then
if [ "refs/heads/${PROTECTED_BRANCH}" = "$REMOTE_REF" ]; then
if [ "$TERM" = "dumb" ]; then
>&2 echo "Sorry, you are unable to push to trunk using a GUI client! Please use git CLI."
exit 1
fi

printf "%sYou're about to push to trunk, is that what you intended? [y/N]: %s" "$(tput setaf 3)" "$(tput sgr0)"
read -r PROCEED < /dev/tty
echo
CURRENT_BRANCH=$(git branch --show-current)
if [ $PROTECTED_BRANCH = $CURRENT_BRANCH ]; then
if [ "$TERM" = "dumb" ]; then
>&2 echo "Sorry, you are unable to push to $PROTECTED_BRANCH using a GUI client! Please use git CLI."
exit 1
fi

if [ "$(echo "${PROCEED:-n}" | tr "[:upper:]" "[:lower:]")" = "y" ]; then
echo "$(tput setaf 2)Brace yourself! Pushing to the trunk branch...$(tput sgr0)"
echo
exit 0
fi
printf "%sYou're about to push to $PROTECTED_BRANCH, is that what you intended? [y/N]: %s" "$(tput setaf 3)" "$(tput sgr0)"
read -r PROCEED < /dev/tty
echo

echo "$(tput setaf 2)Push to trunk cancelled!$(tput sgr0)"
if [ "$(echo "${PROCEED:-n}" | tr "[:upper:]" "[:lower:]")" = "y" ]; then
echo "$(tput setaf 2)Brace yourself! Pushing to the $PROTECTED_BRANCH branch...$(tput sgr0)"
echo
exit 1
exit 0
fi

echo "$(tput setaf 2)Push to $PROTECTED_BRANCH cancelled!$(tput sgr0)"
echo
exit 1
fi

0 comments on commit 7c4c98c

Please sign in to comment.