This repository has been archived on 2021-12-24. You can view files and clone it, but cannot push or open issues/pull-requests.
jos/.hooks/commit-msg

24 lines
732 B
Plaintext
Raw Permalink Normal View History

2021-04-02 14:03:20 +02:00
#!/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`
# This check doesn't need to run when commiting to develop/master
[[ "$branch" =~ ^master|develop$ ]] && exit 0
2021-04-02 14:03:20 +02:00
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" ]] && {
2021-04-02 14:45:04 +02:00
>&2 echo "Couldn't derive issue number from branch. Please add one manually.";
exit 1;
2021-04-02 14:03:20 +02:00
}
2021-04-02 14:45:04 +02:00
# Append issue number, and remove all comments
echo "[#$issue_num]" "$(cat "$1")" > "$1"
2021-04-02 14:03:20 +02:00
fi