Last active
May 24, 2016 16:05
-
-
Save lukleh/7ab241e4e81de0167b124ea0c6c049a4 to your computer and use it in GitHub Desktop.
git commit msg hook to check that branch and commit message start with a number and that the numbers are equal
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
#!/usr/bin/env bash | |
current_branch="$(git rev-parse --abbrev-ref HEAD)" | |
branch_regex='([0-9]+)_.*' | |
if [[ ! $current_branch =~ $branch_regex ]]; then | |
echo "branch does not start with a number" >&2 | |
exit 1 | |
fi | |
branch_num=${BASH_REMATCH[1]} | |
commit_regex='#([0-9]+).*' | |
msg=$(head $1) | |
if [[ ! $msg =~ $commit_regex ]]; then | |
echo $msg "commit does not start with issue number" >&2 | |
exit 1 | |
fi | |
commit_number=${BASH_REMATCH[1]} | |
if [ ! "$branch_num" == "$commit_number" ] | |
then | |
echo "branch number and commit number do not match" $branch_num $commit_number | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment