useful Git hooks for my dev environment
-
-
Save kingargyle/0a6a1a5db4a233d31b05bc62fc83ed1a to your computer and use it in GitHub Desktop.
Git hooks
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/sh | |
commit_regex='^(PP-[0-9]+|fixup!)' | |
error_msg="Aborting commit. Your commit message is missing a JIRA ticket ('PP-1234')" | |
if ! grep -iqE "$commit_regex" "$1"; | |
then | |
echo "$error_msg" >&2 | |
exit 1 | |
fi | |
current_branch="$(git rev-parse --abbrev-ref HEAD)" | |
current_branch_ticket="$(echo $current_branch | grep -P 'PP-[0-9]+' -o)" | |
commit_matches_branch_regex="($current_branch_ticket|fixup!)" | |
if ! grep -iqE "$commit_matches_branch_regex" "$1"; | |
then | |
echo "your JIRA ticket number doesn't match the branch name" >&2 | |
exit 1 | |
fi |
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 | |
# Stops accidental commits to master and develop. https://gist.github.com/stefansundin/9059706 | |
BRANCH=`git rev-parse --abbrev-ref HEAD` | |
if [[ "$BRANCH" == "master" ]]; then | |
echo "You are on branch $BRANCH. Are you sure you want to commit to this branch?" | |
echo "If so, commit with -n to bypass this pre-commit hook." | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment