[misc] Add git-hooks

This commit is contained in:
Thomas Lindner 2020-07-05 23:46:55 +02:00 committed by acipm
parent 16c0d101be
commit 6255452923
4 changed files with 62 additions and 0 deletions

View file

@ -7,6 +7,10 @@
3. Activate your dev environment with `source .venv/bin/activate`
4. Install with `pip install .`
5. Install development dependencies with `pip install tox black`
6. Add git-hook to run test and stylecheck before commmit with
`ln -s ../../git-hooks/pre-commit .git/hooks/pre-commit`
7. Add git-hook to check commmit message format with
`ln -s ../../git-hooks/commit-msg .git/hooks/commit-msg`
### Build and Test Cycle

13
git-hooks/commit-msg Executable file
View file

@ -0,0 +1,13 @@
#!/bin/sh
#
# Copyright (C) 2020 by Thomas Lindner <tom@dl6tom.de>
#
# SPDX-License-Identifier: 0BSD
#
# client-side git-hook - checks commit message style
head -n 1 "$1" | egrep -x '\[[^]]+\] [[:upper:]].*[^.]' > /dev/null
if [ $? -ne 0 ]; then
echo "commit message doesn't match style" >&2
exit 1
fi

9
git-hooks/pre-commit Executable file
View file

@ -0,0 +1,9 @@
#!/bin/sh
#
# Copyright (C) 2020 by Thomas Lindner <tom@dl6tom.de>
#
# SPDX-License-Identifier: 0BSD
#
# client-side git-hook - run tests and stylechecker
exec tox

36
git-hooks/update Executable file
View file

@ -0,0 +1,36 @@
#!/bin/sh
#
# Copyright (C) 2020 by Thomas Lindner <tom@dl6tom.de>
#
# SPDX-License-Identifier: 0BSD
#
# server-side git-hook - checks branch policy
refname="$1"
oldrev="$2"
newrev="$3"
forbid_merge_commmits() {
if [ "$(git log --merges "$oldrev..$newrev")" ]; then
echo "merge commmits not allowed" >&2
exit 1
fi
}
only_ff_to() {
ff_branch="$1"
git rev-list "$oldrev..$ff_branch" | fgrep -x "$newrev" > /dev/null
if [ $? -ne 0 ]; then
echo "only fast-forward to $ff_branch allowed" >&2
exit 1
fi
}
case "$refname" in
refs/heads/master)
only_ff_to development
;;
refs/heads/*)
forbid_merge_commits
;;
esac