Created
July 5, 2022 20:26
-
-
Save neodon/ff35afab6d3e973544371c9d78d72909 to your computer and use it in GitHub Desktop.
Pre-commit hook referenced by Reddit post
This file contains 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-commit | |
# https://www.reddit.com/r/git/comments/3o1tut/precommit_hook_to_make_sure_you_updated_the/ | |
set -o nounset | |
REPO_ROOT=$(git rev-parse --show-toplevel) | |
echo "Git repo is at $REPO_ROOT" | |
SITE_CHANGES=$(git status -s $REPO_ROOT | 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 --cached -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 commit." | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment