diff --git a/.hooks/commit-msg b/.hooks/commit-msg new file mode 100755 index 0000000..ec6c4c9 --- /dev/null +++ b/.hooks/commit-msg @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# This hook checks if the commit message ends with an issue number, and if not, +# tries to derive that number from the branch name + +branch=`git rev-parse --abbrev-ref HEAD` +issue_num=`echo "$branch" | grep -Po '^[0-9]+(?=-)'` + +# Check if issue number is already present +if ! grep -q '([0-9]\+)$' "$1"; then + # Error out if we can't derive issue number + [[ -z "$issue_num" ]] && { + >&2 echo "Couldn't derive issue number from branch. Please add one manually."; exit 1; + } + + # Append issue number + echo "(#$issue_num)" >> "$1" +fi diff --git a/.hooks/pre-commit b/.hooks/pre-commit new file mode 100755 index 0000000..32d1be5 --- /dev/null +++ b/.hooks/pre-commit @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# Just lint the code before committing +make lint