Skip to content

Instantly share code, notes, and snippets.

@kingargyle
Forked from williamdenton/commit-msg
Created April 19, 2019 14:10
Show Gist options
  • Save kingargyle/0a6a1a5db4a233d31b05bc62fc83ed1a to your computer and use it in GitHub Desktop.
Save kingargyle/0a6a1a5db4a233d31b05bc62fc83ed1a to your computer and use it in GitHub Desktop.
Git hooks

useful Git hooks for my dev environment

#!/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
#!/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