2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-22 09:57:41 +00:00
kea/tools/git-hooks/prepare-commit-msg
2020-01-24 17:11:20 +00:00

39 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# This is the branch name (e.g. 29-something or master)
BRANCH=`git branch | grep '^\*' | cut -b3-`
# This is the beginning of the branch name (e.g. 29 for branch being named 29-something).
# It's supposed to start with a issue number.
ISSUE=`git branch | grep -o '^\* [0-9]*' | cut -b3-`
# This is trying to get issue (e.g. 29) from the existing commit message.
# This may be return "" if there commit message doesn't start with [#123]
ISSUEINMSG=`head -n 1 $1 | grep -o '^\[#[0-9]*' | cut -b3-`
# This is for debugging purposes only.
#echo "BRANCH=[$BRANCH] ISSUE=[$ISSUE] ISSUEINMSG=[$ISSUEINMSG]"
if test "$ISSUEINMSG" != ""; then
# There's an issue defined there. It may be different than the branch name,
# but we assume the user knows best *cough*. If we revise this in the future,
# the test could be tightened to "$ISSUEINMSG" != "$ISSUE"
exit 0
fi
if test "$BRANCH" = "master"; then
echo "ERROR: You are on branch $BRANCH"
echo "ERROR: You are not allowed to commit to master directly. Please follow the process"
echo "ERROR: (create issue, then MR for it, ...)"
exit 1
fi
if [ -n "$ISSUE" ]; then
/bin/echo -n "[#$ISSUE] " > "$1.msg"
else
/bin/echo -n "[$BRANCH] " > "$1.msg"
fi
cat "$1" >> "$1.msg"
mv "$1.msg" "$1"