Added git hooks

master
Jef Roosens 2021-04-02 21:08:50 +02:00
parent e60bc35ca2
commit f804c01849
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
2 changed files with 36 additions and 0 deletions

23
.hooks/commit-msg 100755
View File

@ -0,0 +1,23 @@
#!/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
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, and remove all comments
echo "[#$issue_num]" "$(cat "$1")" > "$1"
fi

13
.hooks/pre-commit 100755
View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
# This hook lints the code, and if we're on develop or master, also forces the tests to pass.
branch=`git rev-parse --abbrev-ref HEAD`
# TODO should we add release branches here as well?
if [[ "$branch" =~ ^master|develop$ ]]; then
make test > /dev/null 2>&1 || {
>&2 echo "Tests failed. check 'make test' for more info.";
exit 1;
}
fi