Created
July 5, 2022 20:27
-
-
Save neodon/8b7df6f60cfb620041d8c19fa70665fb to your computer and use it in GitHub Desktop.
Pre-push hook referenced by Reddit post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# .git/hooks/pre-push | |
# https://www.reddit.com/r/git/comments/3o1tut/precommit_hook_to_make_sure_you_updated_the/ | |
set -o nounset | |
set -o errexit | |
REPO_ROOT=$(git rev-parse --show-toplevel) | |
echo "Git repo is at $REPO_ROOT" | |
BRANCH=$(git branch | cut -d' ' -f2) | |
REMOTE=$(git branch -r | xargs) | |
SITE_CHANGES=$(git diff "$BRANCH".."$REMOTE" | wc -l) | |
echo "Detected $SITE_CHANGES changes" | |
if [ "$SITE_CHANGES" -gt "0" ]; then | |
echo "Checking to make sure package version was updated..." | |
VERSION_CHANGED=$(git diff "$BRANCH".."$REMOTE" -G '"version":' -- $REPO_ROOT/package.json | wc -l) | |
if [ "$VERSION_CHANGED" -gt "0" ]; then | |
echo "Version was updated! Continuing..." | |
else | |
echo "Version was not updated :( Aborting push." | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment